Modifying persistent objects in Hibernate by R4R Team

There is no need to call a particular method (like update(), which has a different purpose) to make the application and database modifications persistent.Transactional persistent instances (objects loaded, saved, created or queried by the Session) can be manipulated by the application, and any changes to persistent state will be persisted when the Session is flushed. So we can say that there is no need to call a particular method. The most straightforward way to update the state of an object is to load() it and then manipulate it directly while the Session is open:

DomesticStudent student = (DomesticStudent) session.load( Student.class, new Long(69) );
sess.flush();  //Here changes to student are automatically detected and persisted

In the Hibernate Sometimes the programming model is inefficient, as it requires in the same session both an SQL SELECT to load an object and an SQL UPDATE to persist its updated state. Hibernate offers an alternate approach by using detached instances.

We need to remember the below points in the Hibernate:

1. Hibernate does not offer its own API for direct execution of UPDATE or DELETE statements. 
2. Hibernate is a state management service, you do not have to think in statements to use it. 
3. JDBC is a perfect API for executing SQL statements, you can get a JDBC Connection at any time by calling session.connection(). Furthermore, the notion of mass operations conflicts with object/relational mapping for online transaction processing-oriented applications. 
4. We use the Batch processing for some possible batch operation tricks.
Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!