Difference Between Save and Persist Method in Hibernate by R4R Team

Difference Between Save and Persist Method: In the Hibernate we can say about the difference between save() and persist() method which we use that are define are below:

1. Both are dependent on the generator class which we are using in our application.

2. When we did not assigned the generator class the we can say that time no difference between save() and persist() method both work as same. We can understand about the mean of 'assigned' in generator that is to provide the primary key to save the table in the database.

3. When we did assigned generator class it means that if we take the class name Increment than hibernate it self will assign the primary key id value into the database.

4. All the above cases we call save() or persist() method then it will insert the record into the database normally.

5. save() method can return that primary key id value which is generated by hibernate and we can in below example:

long s = session.save(k);

6. In the same case of the persist() will never give any value return back to the client.

7. we can use persist() method only within the boundary of a transaction, so it’s safe and takes care of any cascaded objects.

8. persist doesn’t return anything so we need to use the persisted object to get the generated 
Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in 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!