-->
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: Lists as indexed bags
PostPosted: Wed Dec 05, 2007 11:03 pm 
Beginner
Beginner

Joined: Fri Sep 28, 2007 9:50 pm
Posts: 34
I read in another thread (http://forum.hibernate.org/viewtopic.php?t=957657) that "A list is an indexed bag", which makes perfect sense. But when an item occurs more than once in a list, and I try to delete one of those occurrences by removing it from the list then updating the list's container with
Code:
session.Update( container );
session.Flush();
NHibernate then throws an exception:
Code:
{"deleted object would be re-saved by cascade (remove deleted object from associations): 43, of class: Test.SampleItem"}


In the mapping file, the list's cascade attribute is set to "all-delete-orphan":
Code:
<class name="SampleListContainer">
...
   <list name="SampleList" table="Item_List" cascade="all-delete-orphan">
      <key column="ListContainerID"/>
      <index column="PosN"/>
      <many-to-many column="ItemID" class="SampleItem"/>
   </list>


What am I getting wrong here?


Hibernate version:
version 1.2.0.GA

Name and version of database:

SQL Server 2005 Express, Service Pack 2


Top
 Profile  
 
 Post subject: multiple parent entities
PostPosted: Thu Dec 06, 2007 12:52 am 
Beginner
Beginner

Joined: Fri Sep 28, 2007 9:50 pm
Posts: 34
It seems I've already solved the problem. I just changed the cascade attribute to "save-update". The reason I had set it to "all-delete-orphan" to begin with, was that I want the SampleItem to be deleted if orphaned. However, "orphaned" in this case pertains to two parent entities: SampleListContainer and another one. I don't think NHibernate supports such semantics directly. So now after updating the deleted item's container, I check whether or not the item still exists in either of the parents and delete it using
Code:
session.Delete( item );
session.Flush();
if not.


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.