Entitymanager merge not updating record
it can do INSERT or UPDATE depending upon whether object exists in database or not.The third method, persist() is similar to Session.save() i.e.The save Or Update() method first executes a SELECT query to determine if it needs to do an INSERT or UPDATE operation.2) Another key difference between save() and save Or Update() method is that former is used to bring a transient object to persistent state but save Our Update() can bring both transient (new) and detached (existing) object into persistent state.based upon your requirement for persisting object into Database.Along with Spring framework Interview questions, Hibernate questions are also quite popular on J2EE interviews because of its status as leading ORM.
One of them is Difference between save , save Or Update and persist, which we will see in this Hibernate article.
It is often used to re-attach a detached object into Session.
Here is an object's lifecycle and state transition diagram in Hibernate which shows that method, the difference between save() and persist() method is that former returns the generated database identifier, a Serializable object but persist() method doesn't return anything. For example: That's all about difference between save(), save Or Update() and persist() method of Hibernate Session interface.
it is used to move a transient object to the persistent state by storing it into the database but it doesn't return the database identifier.
This was the basic difference between save() vs save Or Update() vs persist() method and suggest when to use which method.