-->
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.  [ 4 posts ] 
Author Message
 Post subject: cannot saveOrUpdate entity
PostPosted: Sat Feb 23, 2008 10:18 am 
Newbie

Joined: Sat Feb 23, 2008 9:57 am
Posts: 3
Hi,

I'm facing a problem with Hibernate 3.2.1 GA tied with Spring framework. I think the problem is due to how I use Hibernate.

1- I load an object A (Class C id 1) through a Hibernate Session.
2- I store object A in memory.
3- In a transaction, I open a new Hibernate Session
4- In this Hibernate Session, I load a lof of objects including a similar object than A (Class C id 1).
5- After some operations, I want to saveOrUpdate object A referenced in step 1 : Hibernate throw an exception :

a different object with the same identifier value was already associated with the session: [com.mycompany.mypackage.MyClass#1]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.mycompany.mypackage.MyClass#1]

What's wrong ? How can I solve this problem ?

Thanks a lot !

Regards,
E. Lewandowski


Top
 Profile  
 
 Post subject: Re: cannot saveOrUpdate entity
PostPosted: Sat Feb 23, 2008 12:09 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Which object has the latest data? If both can have modifications then you have to somehow merge these modifications otherwise evict the object first and then update it with what you know that should be in the database.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 23, 2008 9:47 pm 
Newbie

Joined: Sat Feb 23, 2008 9:57 am
Posts: 3
Thanks Farzad

Object loaded in step 4 is an read-only object. I may remove it from the hibernate session is needed. It has no modification.

I have no reference on this object : it is in the session but never user. How can I evict him ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 23, 2008 10:15 pm 
Newbie

Joined: Sat Feb 23, 2008 9:57 am
Posts: 3
Farzad, the information solved my problem.

I just retrieve a reference to the object in the Hibernate session and evict it.

Object pDuplica = pSession.get(entite.getClass(), entite.getIdEvltnAutnm());

if (pDuplica != null) {
pSession.evict(pDuplica);
}

After, I can save my object (entite) with no problem.

Thanks a lot !


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