-->
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: Composit-Association Mapping?
PostPosted: Mon Jan 09, 2006 12:00 pm 
Newbie

Joined: Sun Jan 08, 2006 2:26 pm
Posts: 15
Hi there,

i was searching the Forum on this topic, but didnt find anything relating. Maybe there is already an thread and u just can post the link? :-)

In my domainmodel i´ve got an unidirectional 1:many composit association between Order and OrderDetails. E.g. Order is implementing an ArrayList of OrderDetails. How do i map this best? Should I use an unidirectional Parent/Child-Associaton cause component is not working for Colections?

in Order.hbm.xml something like:

<class name="NHTest.Order", NHTest....>
...
<set name="Details">
<key column="DetailsId"/>
<one-to-many class="NHTest.OrderDetails, NHTest/>
</set>
...
...
</class>

In the documentation is just the bidirectional case explained. Thx for any tips on this, i know i am an beginner :-)

Chris


Top
 Profile  
 
 Post subject: some ideas
PostPosted: Mon Jan 09, 2006 9:56 pm 
Newbie

Joined: Thu Jan 05, 2006 7:33 pm
Posts: 13
That sounds pretty straight forward. If you want a one way one-to-many relationship between 2 different objects (such as an order and order details) the most common approach is using the <many-to-many> tag with unique="true", inside a collection tag. For the collection you can use most collection types including maps, lists or sets. You use a <many-to-many> because this creates a seperate joining table between the two seperate class tables. The <one-to-many> tag only defines a link that uses foreign keys, which is an uncommon approach but possible.

Code:
eg

<list name="orderDetails">   // the name of the property
    <key column="orderId"/>  // just a column name - not critical
    <many-to-many class="OrderDetails" unique="true"/>
</list>



The general idea is summarised at the unidirectional one-to-many entry at:
http://www.hibernate.org/hib_docs/v3/re ... l-join-12m


There is one example of a similar case to yours in the hibernate docs at:
http://www.hibernate.org/hib_docs/v3/re ... derproduct

happy hibernating

Michael


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 8:56 am 
Newbie

Joined: Sun Jan 08, 2006 2:26 pm
Posts: 15
Thx that link and example helps a lot!
Chris


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.