-->
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: Problem with many-to-many relationship and inverse flag
PostPosted: Fri Mar 09, 2007 8:45 pm 
Newbie

Joined: Fri Mar 09, 2007 8:21 pm
Posts: 1
Hi Guys,

Facing a serious problem with many-to-many relationship with a link table between two master tables.

I have a Customer Table and a Group Table and the relationship is many-to-many thereby


Customer(customers)[0...*]------------------customerGroup--------------------Group(groups))[0...*]


the HBM declarations are as follows:

In Customer.hbm.xml

....
<set name="groups"
table="CUSTOMER_GROUP"
order-by="GROUPS_FK" lazy="true"
fetch="select" inverse="false">

<key foreign-key="GROUP_CUSTOMER_FC">
<column name="CUSTOMER_FK" sql-type="VARCHAR(36)"/>
</key>
<many-to-many class="com.test.Group"
foreign-key="CUSTOMER_GROUPS_FKC">
<column name="GROUPS_FK" sql-type="VARCHAR(36)"/>
</many-to-many>
</set>
....

In Group.hbm.xml

...
<set name="customers"
table="CUSTOMER_GROUP"
order-by="CUSTOMERS_FK" lazy="true"
fetch="select" inverse="true" >

<key foreign-key="CUSTOMER_GROUP_FKC">
<column name="GROUPS_FK" sql-type="VARCHAR(36)"/>
</key>
<many-to-many
class="com.test.Customer"
foreign-key="GROUP_CUSTOMERS_FC">
<column name="CUSTOMERS_FK"
sql-type="VARCHAR(36)"/>
</many-to-many>
</set>
....

Since inverse is true on Customer, it should update the link table and not Group, is this assumption correct?

If I flip the flags, no updates happen to the link table.

Any help would be appreciated.

- Kingfisher.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 10, 2007 4:44 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
It'll probably help if you show the java code where you are doing the updates.

Anyway, given the two mapping files you have,

If you do
Code:
Group newGroup = new Group();
Customer customer = ...;
customer.getGroups().add(new Group());

The link table will be updated.

If you flip the inverse flag, you'd need to do
Code:
newGroup.getCustomers().add(customer);

on top of the previous snippet in order for the link table to be updated.

Budyanto

[/code]


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.