-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Entities saved, not updated.
PostPosted: Tue Oct 24, 2006 11:14 am 
Newbie

Joined: Fri Aug 04, 2006 3:01 pm
Posts: 13
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


Top
 Profile  
 
 Post subject: Forget it...
PostPosted: Tue Oct 24, 2006 1:00 pm 
Newbie

Joined: Fri Aug 04, 2006 3:01 pm
Posts: 13
Solved. Just for the record, use session.merge(object);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.