-->
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: Multiple Composite IDs
PostPosted: Thu Jan 08, 2004 7:40 pm 
Newbie

Joined: Thu Jan 08, 2004 7:30 pm
Posts: 2
I have a seemingly simple relationship. I have ContentItem with a composite ID (md_id, lang_id), both are type 'long'. I have a ContentBranch object that also has a composite ID (branch_id, lang_id), both are type 'long'. I have an associating table that has three columns (md_id, lang_id, branch_id) and I am having trouble creating the relationship that I want in the mapping file.

Here is branch:

<!-- Branch -->
<class name="com.company.project.Branch" table="mdwfbranch">
<meta attribute="class-description" inherit="false">
This class holds all available metadata branches
</meta>
<jcs-cache usage="read-only"/>
<composite-id>
<key-property name="id" type="long" column="branch_id"/>
<key-property name="langid" type="long" column="lang_id"/>
</composite-id>
<many-to-one name="language" column="lang_id" class="com.company.project.Language" cascade="none" not-null="true" insert="false" update="false"/>
<property name="description" type="string">
<column name="description" length="40" not-null="true" unique="true"/>
</property>
<property name="active" type="boolean">
<column name="active" index="mdWFBranch_idx01" not-null="true"/>
</property>
</class>

Branch works perfectly alone.

ContentItem:

<class name="com.company.project.ContentItem" table="mdcontent">
<meta attribute="class-description" inherit="false">
This class contains the needed metadata information for each studio tip
</meta>
<jcs-cache usage="read-only"/>
<composite-id>
<key-property name="id" type="long" column="md_id"/>
<key-property name="langid" type="long" column="lang_id"/>
</composite-id>

<many-to-one name="level" class="com.company.project.ContentLevel" insert="false" update="false">
<column name="level_id" not-null="true"/>
<column name="lang_id" not-null="true"/>
</many-to-one>

<many-to-one name="type" class="com.company.project.ContentType" insert="false" update="false">
<column name="type_id" not-null="true"/>
<column name="lang_id" not-null="true"/>
</many-to-one>

<set name="branches" table="mdbranchchild" lazy="true">
<key>
<column name="md_id" not-null="true"/>
<column name="lang_id" not-null="true"/>
</key>
<many-to-many class="com.company.project.Branch">
<column name="branch_id" not-null="true"/>
<column name="lang_id" not-null="true"/>
</many-to-many>
</set>

</class>

It throws an exception on the set because "lang_id" is repeated.


Top
 Profile  
 
 Post subject: Update
PostPosted: Fri Jan 09, 2004 5:12 pm 
Newbie

Joined: Thu Jan 08, 2004 7:30 pm
Posts: 2
I found a solution by adding an additional column to the relational table. I added a 'branch_lang_id" to the table. So, what I have now is a relational table with these fields: md_id, lang_id, branch_id, branch_lang_id

This works, but I have to maintain two columns with exactly the same data. I would never want to link a content item that is English with a Branch that is Japanese. I wanted to use the same column in both composite ID's but Hibernate would not allow it in the mapping file.

Is there any other way that I could have acheived what I wanted without creating the additional column?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 7:46 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
I have asked for something similar before: http://forum.hibernate.org/viewtopic.php?t=925446

Maybe, if more people want it, it will be implemented... :)


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.