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.  [ 5 posts ] 
Author Message
 Post subject: Mapping many-to-many association using List
PostPosted: Fri May 25, 2007 5:43 am 
Newbie

Joined: Tue Mar 27, 2007 11:34 pm
Posts: 13
Hi all,
I have a question about mapping a many-to-many association using list. Suppose I have a schema like that :
Customer {id : int}
Account {id : int}
Customer_Account {CustomerID : int, AccountID : int, CustomerIndex : int, AccountIndex : int}

now I mapped the association using list :

In Customer mapping:
Code:
<list name="accounts" table="Customer_Account" cascade="save-update,lock">
    <key column="AccountID" not-null="true"/>
    <list-index column="AccountIndex"/>
    <many-to-many column="CustomerID" class="Customer"/>
</list>


In Account mapping:
Code:
<list name="customers" table="Customer_Account" cascade="save-update,lock">
    <key column="CustomerID" not-null="true"/>
    <list-index column="CustomerIndex"/>
    <many-to-many column="AccountID" class="Account"/>
</list>


When I saving the customer object, it only insert the CustomerID, CustomerIndex and AccountID into the database, did anyone know whats wrong with it?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 6:53 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

use inverse=true in
Code:
<list name="customers" table="Customer_Account" cascade="save-update,lock">



Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 11:28 pm 
Newbie

Joined: Tue Mar 27, 2007 11:34 pm
Posts: 13
Thanks for your advance.

But I still got the following problems:
1. specify inverse="true" in customer side => will only insert AccountIndex
2. specify inverse="true" in account side => will only insert CustomerIndex
3. specify inverse="true" in other side => it will insert the record twice, first record is inserting CustomerIndex, another one is AccountIndex.


Is it have anyway to insert only one record and specify both index column??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 5:42 am 
Newbie

Joined: Tue Mar 27, 2007 11:34 pm
Posts: 13
Is there have any solution for this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 2:41 pm 
Newbie

Joined: Fri Jun 15, 2007 2:35 pm
Posts: 1
You have your associations backwards. In Customer you want a list of Account objects, not Customer objects. It should look like this:


In Customer mapping:

<list name="accounts" table="Customer_Account" cascade="save-update,lock">
<key column="CustomerID" not-null="true"/>
<list-index column="AccountIndex"/>
<many-to-many column="AccountID" class="Account"/>
</list>


And the same thing for Account

In Account mapping:

<list name="customers" table="Customer_Account" cascade="save-update,lock">
<key column="AccountID" not-null="true"/>
<list-index column="CustomerIndex "/>
<many-to-many column="CustomerID" class="Customer"/>

</list>


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