Isaac Goldstein wrote:
Hibernate version: 3.2.5
We've being using Hibernate for many years now and we love it. Recently, we found that the Hibernate Entity Manager - when asked to merge using a long transaction - will actually load the object again from the database (if its not available in the first or second level cache). Why does it do this? Why does it not simply use the detached object? Hibernate saveOrUpdate doesn't load the object, why does merge?
In addition to inefficiency, this causes problems when you load object using native queries. Hibernate will generate its own query during merge and this may clash with the mapping.
I miss the older, simpler Hibernate days...
It has something to do with semantics of merge. It is hard for a container to track all changes in an object while it has been detached. Look at section 10.7. Automatic state detection of hibernate documentation. You might want to use a different method rather than merge.
Farzad-