Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1090805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:25:35+00:00 2026-05-16T23:25:35+00:00

I learnt Hibernate and used it to reduce my Java code to a vast

  • 0

I learnt Hibernate and used it to reduce my Java code to a vast extent and also able
to reduce the time spent for DB’s. Now what type of query should i use to finish my
operations for getting a DB list to be displayed, to update and delete.

My code for deletion is

String newToken = "DELETEUSER";
if(!TokenManager.checkRoleToken(newToken)){
    return;
}
Session session = Main.getSession(); //calling the main method to get sesion 
Leavetable table = new Leavetable; // intialisation of object table
try{
    Transaction tr = session.beginTransaction();
    table = session.createQuery();
    session.delete(table); // deletion of the object and its properties  from selected leaveID
    tr.commit();            
}
finally{
    session.close();
}

My code for Db updation

public void updateLeaveTable( Leavetable leave ) {
    String newToken = "ADDUSER";
    if( !TokenManager.checkRoleToken( newToken ) ) {
        return;
    }
    Session session = Main.getSession(); // calling the main method to get
                                         // session
    try {
        session = Main.getSession();
        Transaction tr = session.beginTransaction();
        session.saveOrUpdate( leave ); // here without query the table gets
                                       // updated How?
        tr.commit();
    }
    finally {
        session.close();
    }
}

What type of query should I follow. My final task before going into project. When I
know this will start my life as a developer. Any suggestions Please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:25:35+00:00Added an answer on May 16, 2026 at 11:25 pm

    Do you mean a HQL query? Well, a typical query on your Leavetable entity would looks like this:

    Query q = session.createQuery("from Leavetable t where t.someField = :value");
    q.setParameter("value", foo);
    List<Leavetable> results = q.list();
    

    However, if you just want to retrieve an entity by identifier, see Session#load() or Session#get(). I don’t want to make things too much confusing but while both methods are similar, there is an important difference between both of them. Quoting the Hibernate Forums:

    Retrieving objects by identifier

    The following Hibernate code snippet
    retrieves a User object from the
    database:

    User user = (User) session.get(User.class, userID);
    

    The get() method is special because
    the identifier uniquely identifies a
    single instance of a class. Hence it’s
    common for applications to use the
    identifier as a convenient handle to a
    persistent object. Retrieval by
    identifier can use the cache when
    retrieving an object, avoiding a
    database hit if the object is already
    cached. Hibernate also provides a
    load() method:

    User user = (User) session.load(User.class, userID);
    

    The load() method is older; get() was
    added to Hibernate’s API due to user
    request. The difference is trivial:

    If load() can’t find the object in
    the cache or database, an exception is
    thrown. The load() method never
    returns null. The get() method
    returns null if the object can’t be
    found.

    The load() method may return a proxy
    instead of a real persistent instance.
    A proxy is a placeholder that triggers
    the loading of the real object when
    it’s accessed for the first time; we
    discuss proxies later in this section.
    On the other hand, get() never
    returns a proxy.

    Choosing between get() and load()
    is easy:
    If you’re certain the
    persistent object exists, and
    nonexistence would be considered
    exceptional, load() is a good
    option. If you aren’t certain there is
    a persistent instance with the given
    identifier, use get() and test the
    return value to see if it’s null.
    Using load() has a further
    implication: The application may
    retrieve a valid reference (a proxy)
    to a persistent instance without
    hitting the database to retrieve its
    persistent state. So load() might
    not throw an exception when it doesn’t
    find the persistent object in the
    cache or database; the exception would
    be thrown later, when the proxy is
    accessed.

    Of course, retrieving an object by
    identifier isn’t as flexible as using
    arbitrary queries.

    See also the Hibernate Documentation (links below).

    Reference

    • Hibernate Core Reference Guide
      • 10.3. Loading an object
      • Chapter 14. HQL: The Hibernate Query Language
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I learnt JPA for ORM. Now I am asked to use Hibernate as my
i am trying to learn Java, Hibernate and the MVC pattern. Following various tutorial
I'm writing a Java web app in my free time to learn more about
I'm just starting to learn Java database persistence using Hibernate ORM and have run
In the future I will be working with MVC with java/j2ee,hibernate,and more, but for
I've been trying to learn spring and hibernate, and I've used a lot of
In the last time I heard a lot of complaining about Hibernate. And indeed
I'm using : Eclipse Java EE IDE Web Developers version:Indigo Release with hibernate tools,
I am trying to learn Hibernate from Java Persistence with hibernate by Gavin King.
Right now i want to make a small java application, in order to learn

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.