-->
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: Composite Pattern and Composite IDs
PostPosted: Tue May 18, 2004 10:30 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
We are trying to apply the composite pattern to an Entity which has a composite ID.

(For the purpose of this question, please assume that we cannot use surrogate keys)

Please consider the following:

Entity Parent has composite-id A,B
Parent can have many children of type Parent

Question:

Could someone demonstrate how to map this type of association? We currently have an association table representing the many-to-many relationship. If not using a surrogate key, we design this table with a four column foreign key and our attempts at mapping the many-to-many collection from the parent Entity have failed.

We've sifted through the forum and understand all to well the argument regarding surrogate keys from the Hibernate Team. However, we'd appreciate if someone could describe how to map this relationship correctly without the usage of a surrogate key (if at all possible).

Regards,
Roll


Top
 Profile  
 
 Post subject: Composite Pattern and Composite IDs
PostPosted: Tue May 18, 2004 10:45 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
Sorry where it reads "we design this table with a four column foreign key" I intended to write "we design this table with a four column composite key".


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 11:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Something like:

Code:
<class name="Parent" ...>
    <composite-id name="id" class="ParentPK" unsaved-value="none">
        <key-property name="pkAttr1" column="pk_col_1" .../>
        <key-property name="pkAttr2" column="pk_col_2" .../>
    </composite-id>
    ...
    <set name="children" lazy="true" table="messy_association_table" ...>
        <key>
            <column name="prnt_attr_1"/>
            <column name="prnt_attr_2"/>
        </key>
        <many-to-many class="Parent">
            <column name="child_attr_1"/>
            <column name="child_attr_2"/>
        </many-to-many>
    </set>
</class>


And yes, this is all covered in the docs http://www.hibernate.org/hib_docs/reference/en/html/components.html#components-compositeid


Top
 Profile  
 
 Post subject: Composite Pattern and Composite IDs
PostPosted: Wed May 19, 2004 12:59 am 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
"messy" indeed.

Cheers,
Roll


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.