-->
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: Nhibernate does not update connection table in M:M
PostPosted: Mon Jan 30, 2006 11:33 am 
Newbie

Joined: Mon Oct 10, 2005 1:55 pm
Posts: 12
hi all
Im using Nhibernate in order to map my Classes in to DB. my problem is that when i Insert an Entity which relates with M:M to another Entity - the Entities are being inserted correctly but the connection table are not being updated with the 2 entities ID's. i am is there any mapping property that may prevent Nhibernate to update the connection table???
Thnks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 11:40 am 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
Can you post your mapping file for this relationship?

Also, do you have it mapped as a bidirectional relationship? If so, do you have an Inverse side specified?

_________________
-Chris


Top
 Profile  
 
 Post subject: the mapping for your request
PostPosted: Tue Jan 31, 2006 3:49 am 
Newbie

Joined: Mon Oct 10, 2005 1:55 pm
Posts: 12
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace ="aaa.bbba.ccc" assembly="aaa.bbb.ccc.Impl">

<class name="Left" table="IntLefts" >

<id name="OIID" column="OIID" unsaved-value="00000000000000000000000000000000" type="String" >
<generator class="uuid.hex" />
</id>


<property name="ID" column="ID" type="Int32" />


<!-- Entity Specific Property -->
<property name="Name" column="Name" type="String" />

<!--Internals-->
<!--1:m-->




<!--m:m-->
<bag name="rights" table ="INTLEFTRIGHTS" inverse="true" cascade="all-delete-orphan" access="field" >
<key column="INTLEFTOIID"/>
<many-to-many class="right" column ="INTRIGHTOIID"/>
</bag>





<!--m:1-->

</class>
</hibernate-mapping>







<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace ="aaa.bbba.ccc" assembly="aaa.bbb.ccc.Impl">
<class name="Right" table="IntRight">

<id name="OIID" column="OIID" unsaved-value="00000000000000000000000000000000" type="String" >
<generator class="uuid.hex" />
</id>


<!-- Versionable Entity Properties -->
<property name="ID" column="ID" type="Int32" />

<!-- Entity Specific Property -->
<property name="Name" column="Name" type="String" />

<!--Internals-->

<!--m:m-->
<!--
<bag name="lefts" table ="INTLEFTRIGHTS" inverse="true" access="field" cascade="all-delete-orphan">
<key column="INTRIGHTOIID"/>
<many-to-many class="left" column ="INTLEFTOIID"/>
</bag>



<!--Externals-->
</class>
</hibernate-mapping>



those 2 mappings represent the M:M relationship - Nhibernate updates the M table but not the connection table
thnks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 9:35 am 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
I noticed in each relationship mapping, that you have inverse="true". You should only specify one side as having inverse="true" instead of both. Here's a quote from the Hibernate manual:
Quote:
Changes made only to the inverse end of the association are not persisted.


That may explain why you aren't seeing that relationship table being updated.

_________________
-Chris


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.