Hi there,
I have an entity which is fetched earlier in the program, and when I try to update it, it saves a copy instead.
I'm in a particular situation. Those operations take place in a separate thread but uses the same data access services as the original app.
Here's what I do :
Code:
org.hibernate.Session session = sessionFactory.openSession();
Transaction t1= session.beginTransaction();
(...)
List<Etudiant> liste = this.etudiantManager.getEtudiantsPourEnvoi(e.getEnquete().getId());
t1.commit();
(... modifications are made to the objects ... )
Transaction t2= session.beginTransaction();
session.save( an object from the list );
t2.commit();
It inserts my object instead of updating it. This decision is made from the following line of code in org.hibernate.event.def.DefaultSaveEventListener:22 :
Code:
EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() );
if ( entry!=null && entry.getStatus() != Status.DELETED ) {
return entityIsPersistent(event);
}
else {
return entityIsTransient(event);
}
So it means that my object was not present in the session.
It is important to know that there is an interceptor on the call to the data service which opens sessions. It's the Spring Transaction Interceptor.
How can I merge my objects to the sesison so they can be updated ? But most importantly, why aren't they included in the first place ??
Hibernate version:
3.2.0 CR5