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.  [ 1 post ] 
Author Message
 Post subject: Many-to-many again
PostPosted: Tue Sep 16, 2008 2:43 am 
Newbie

Joined: Mon Jul 14, 2008 7:08 am
Posts: 18
I have two entities:
Code:
class Entity1
{
...
public virtual IList<Entity2> E2List{ get; set; }
...
}

class Entity2
{
...
public virtual IList<Entity1> E1List{ get; set; }
...
}

They should be connection using bidirectional many-to-many. This is mappings:
Code:
<class name="Entity1"....
<bag name="E2List" lazy="false" cascade="none" table="Entity1_Entity2" inverse="true">
<key><column name="Entity1Id" not-null="true" /></key>
<many-to-many class="Entity2" column="Entity2Id"/>
</bag>
</class>

<class name="Entity2"....
<bag name="E1List" lazy="false" cascade="none" table="Entity1_Entity2" inverse="false">
<key><column name="Entity2Id" not-null="true" /></key>
<many-to-many class="Entity1" column="Entity1Id"/>
</bag>
</class>

I want the following behaviour:
1)When I delete Entity1Instance I want all records in Entity1_Entity2, which references Entity1Instance, be deleted.
2)And contrary: when I delete
Entity2Instance I want all records in Entity1_Entity2, which references Entity2Instance, be deleted.

I discovered that inverse attribute plays important role in this: if I set inverse="true" for Entity1 (as in example) I have 2nd behaviour and if I set inverse="true" for Entity2 I have 1st behaviour. So I can reproduce only 1st or 2nd behavoiur but not both.
Please help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.