-->
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: Persisted object as a local variable
PostPosted: Mon Apr 17, 2006 11:04 pm 
Newbie

Joined: Tue Mar 21, 2006 1:56 am
Posts: 4
I do a retreive on an object like: Person[] persons = Person.FindAll();
then i pass an object ot a class like: class PersonProcessor{
private Person person;
PersonProcessor(Person p) {
this.person = p; //SOURCE OF ERROR
}

I make a call like:new PersonProcessor(persons[0]);

Due to that variable assigment I will always get a
Could not perform Save for Person-a different object with the same identifier value was already associated with the session: c2d00de1-65e8-464f-907f-d3eeeb9588b6, of class: Unicru.Persistence.BusinessObjects.Person

no matter what any subsequent method wants to do to the local person object. I think this is due to the fact the because of the Find() call all of those person objects are loaded into the session. okay, but why cant I assign a local variable to one of those persisted objects and act on it ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 4:48 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
If an instance of the "same" Person object (same ID) is already in the NHibernate session you're using to save the Person instance you pass to your PersonProcessor class, then your PersonProcessor class would need to either remove the "old" instance in its session using Evict(), or save the passed-in person using SaveOrUpdateCopy(). I think Evict() will hose things up by removing referenced entities from the session (probably not what you want), so try SaveOrUpdateCopy().


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.