• Register

Share:- Whatsapp Facebook Facebook

------------------------------------- Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

0 votes
350 views
What is difference between save and persist in hibernate ?
in Hibernate by

1 Answer

0 votes

There are following difference between save and persist method in hibernate:

save():
1) The save() method generates a new identifier and INSERT record into database.
2) This method saves records into database by generating INSERT SQL query.
3) It generates a new identifier and return the Serializable identifier back.
4) It returns a Serializable object.
5) The save() method in Hibernate is that is there behavior on outside of transaction boundaries.

persist():
1) The persist() method is similar to save() method, it also INSERT records into database but return type of persist is void.
2) The persist() method doesn't guarantee that the identifier value will be assigned to the persistent instance immediately, the assignment might happen at the time of flushing.
3) The persist() method guarantees, it will not execute an INSERT statement when you called outside of transaction boundaries.

by
...