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.  [ 6 posts ] 
Author Message
 Post subject: Load and save an object in the same session and transaction
PostPosted: Thu Dec 18, 2003 7:19 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
Dear all,
I load an object, I modify it and I want to update it. But when I update it I have the following message error :
Code:
Another object was associated with this id (the object with the given id was already loaded): [fr.gouv.finances.dgi.opale.commun.transverse.persistent.AdherentPersistent#20030100001243]


Any idea ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 8:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
A loaded object instance need not to be reattached to the session (session.update())

Looks like you do
Code:
myClass1 = (MyClass) session.load(MyClass, id)
myClass2.setId(id); //same id than myClass1
session.update(myClass2);

You must update myClass1 or evict it from the session

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 11:37 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
And how can I evict it from session, close the session ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 12:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
session.evict()

Try saveOrUpdateCopy, should be better in your case

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2003 9:17 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
If I use session.evict(myObject) I have the same error ans saveOrUpdateCopy doesn't exist in my release !


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2003 1:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
gbonnard wrote:
If I use session.evict(myObject) I have the same error ans saveOrUpdateCopy doesn't exist in my release !

You must evict the object which is actually attached with the session. ie the session.load(MyClass, id) object. The other one isn't attached to the session, and that's the problem

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.