The associated objects are also persisted or updated if cascade is defined as "save-update". save Or Update(Object object): Accepts the instance of new entity or any detached object from the session to save or update. update can fail if an instance of the object is already in the session. It merges the changes of the detached object with an object in the session, if it exists.Update: Suppose we are dealing with any employee object in the same session then we should use update() or save Or Update() method.Hibernate provides multiple methods for persisting entities with slightly different semantics.
In order //to avoid this exception we are using merge like given below instead of session.update(emp1); session2.merge(emp1); //it merge the object state with emp2 session2.update(emp1); //Now it will work with exception In the hibernate session we can maintain only one employee object in persistent state with same primary key, while converting a detached object into persistent, if already that session has a persistent object with the same primary key then hibernate throws an Exception whenever update() method is called to reattach a detached object with a session.Control flow analysis has become much smarter and now detects a wider variety of problems in the code.For example, if Collection#is Empty() returns true, the IDE understands that there are no elements in that collection to iterate over.The IDE also understands that String#char At(int index) throws an exception when called with an empty string, or when the index exceeds the value returned by the String#length() method.The same intelligence applies to: String#is Empty(), String#char At(int index), List#get(int index), Set#contains(Object item), Map#contains Key(Object key), Map#contains Value(Object value), and many other methods.