-->
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: Updating a bag ...
PostPosted: Mon Mar 19, 2007 1:09 pm 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:03 pm
Posts: 22
Hibernate version:
1.2.0.CR1


Hello all...
My mapping documents:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="X" table="tblX" lazy="false">

    <id name="IdX" column="id" type="Int32" unsaved-value="0">
      <generator class="identity"/>
    </id>

    <bag name="lpath" generic="true" access="field" table="tblY" inverse="true" lazy="false" cascade="all-delete-orphan">
      <key column ="IdX"></key>
      <one-to-many class ="Y" />
    </bag>
   
  </class>
</hibernate-mapping>





The insert works great...
The problem occurs when I try to update the X class...
To do that, first I load a X´s entity :
...
X _x = session.Load(persitentType,id);
...

After that I change my path´s list (lPath), like that :

Code:
List<Path> _l = (List<Path>)Session["PATH_LIST"];
_x.Path.Clear();
_x.Path = _l;
session.SaveOrUpdate(_x);


So, I got the following error:


a different object with the same identifier value was already associated with the session: 1, of class: Y

Any ideas?

ty


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 6:57 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
you can't just replace a collection like that, you would need to do something like:

Code:
List<Path> _l = (List<Path>)Session["PATH_LIST"];
_x.Path.Clear();
foreach (Path p in _l)
  _x.Path.Add(p);
  // and possiblly
  // p.X = _x;
session.SaveOrUpdate(_x);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 8:39 am 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:03 pm
Posts: 22
devonl wrote:
you can't just replace a collection like that, you would need to do something like:

Code:
List<Path> _l = (List<Path>)Session["PATH_LIST"];
_x.Path.Clear();
foreach (Path p in _l)
  _x.Path.Add(p);
  // and possiblly
  // p.X = _x;
session.SaveOrUpdate(_x);



I did that
Code:
foreach (Path p in _l)
{
                p.X = _x;
               _x.Path.Add(p);               
}


And I got the same error ! :(

a different object with the same identifier value was already associated with the session: 1, of class: Y


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 20, 2007 1:51 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
okay, please post your class definition and the mapping file.


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.