• 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
1.8k views
difference between persist and saveorupdate in hibernate
in Hibernate by

1 Answer

0 votes

There are following difference between persist and saveorupdate in hibernate:

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.

saveOrUpdate():
1) The saveOrUpdate() method can either INSERT or UPDATE records based upon existence.
2) The saveOrUpdate is more flexible to use but it involves an extra processing to find whether record is already exists in table or not.
3) The saveOrUpdate() method either INSERT or UPDATE records based upon existence of object in database. If persistence object is already exists in database then UPDATE SQL will execute and if do not found object in database than INSERT will run.
 

by
...