-->
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.  [ 3 posts ] 
Author Message
 Post subject: many-to-many mapping inserting duplicate rows
PostPosted: Mon May 10, 2004 2:52 pm 
Newbie

Joined: Mon May 10, 2004 2:28 pm
Posts: 10
Location: Seattle, WA
First off I'd like to apologise if this question has been answered elsewhere. I've looked on the forums but nothing doing.

I am trying a prototype out which has a many-to-many relationship. I have two tables Roles and Principals and a join table role_principals.

My mapping is as follows:

<hibernate-mapping
package="liquid">

<class name="Principal" table="principals">
<id name="id" column="id">
<generator class="uuid.hex"/>
</id>

<property name="firstName" column="FIRST_NAME" not-null="false"/>
<property name="lastName" column="LAST_NAME" not-null="false"/>

<set name="roles" table="role_principals" lazy="true">
<key>
<column name="principal_id" not-null="true"/>
</key>
<many-to-many class="Role">
<column name="role_id" not-null="true"/>
</many-to-many>
</set>

</class>

</hibernate-mapping>

<hibernate-mapping
package="liquid">

<class name="Role" table="roles">
<id name="id" column="id">
<generator class="uuid.hex"/>
</id>

<property name="name" column="name" not-null="false"/>

<many-to-one name="ruleset" class="Ruleset" cascade="all" not-null="true" column="ruleset_id"/>

<set name="principals" table="role_principals" lazy="true">
<key>
<column name="role_id" not-null="true"/>
</key>
<many-to-many class="Principal">
<column name="principal_id" not-null="true"/>
</many-to-many>
</set>

</class>

</hibernate-mapping>

The problem that I'm having is that when I set the 'principals' on the Role and AND set the 'roles' on the Principal end I get two identical records in the role_principals table.

I can update it only on one end but then I can't navigate from both objects.


Any help would be very gratefully received.

Ian.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 2:53 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Set one side of the association inverse="true", which <set> doesn't matter in your case.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Mon May 10, 2004 3:37 pm 
Newbie

Joined: Mon May 10, 2004 2:28 pm
Posts: 10
Location: Seattle, WA
Christian,

That did it. Thanks very much.

Ian.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.