Entitymanager merge not updating record
Also, calling merge for managed entities is also a mistake since managed entities are automatically managed by Hibernate and their state is synchronized with the database record by the dirty checking mechanism upon flushing the Persistence Context.
To understand how all this works, you should first know that Hibernate shifts the developer mindset from SQL statements to entity state transitions.
So hibernate creating new record for the userdetails without signaling any error.
So it have set the id field of Userdeatils with existing Id value of the record to which we want to apply the update operation.
If the provider did not update the Employee instance in the persistence context, any references to that instance will become inconsistent with the new state being merged in.
When merge() is invoked on a new entity, it behaves similarly to the persist() operation.
Some providers might allow the managed copy to point to the non-persistent object, whereas others might throw an exception immediately.
What I would do was in a separate request, retrieve the entity from session and then try to access a collection in my jsp page which was problematic.
Once an entity is actively managed by Hibernate, all changes are going to be automatically propagated to the database. But for an entity to become managed, it must be in the right entity state.
First, we must define all entity states: The merge is going to copy the detached entity state (source) to a managed entity instance (destination).
Spitter spitter=new Spitter(); Spittle spittle3=new Spittle(); Username("George"); Password("test1234"); spittle3Spittle("I love java 2"); spittle3Spitter(spitter); Spittle(spittle3); // Spitter spitter=new Spitter(); Spittle spittle3=new Spittle(); Username("George"); Password("test1234"); spittle3Spittle("I love java 2"); spittle3Spitter(spitter); dao.save(spittle3); // Although if connected to My SQL merge() could be as efficient as persist() using a call to INSERT with ON DUPLICATE KEY UPDATE option, JPA is a very high level programming and you can't assume this is going to be the case everywhere.
If you're using the assigned generator, using merge instead of persist can cause a redundant SQL statement, therefore affecting performance.