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.  [ 1 post ] 
Author Message
 Post subject: <composite-id> with two key elements on the same objec
PostPosted: Fri Jun 08, 2007 9:36 am 
Newbie

Joined: Thu May 17, 2007 5:27 am
Posts: 1
Hi,

Hibernate version: 3.2.4

I have a map table that has columns like the following:

TABLE (
obj1_row_id,
obj1_item_id,
obj2_id
)

This has the following hibernate mapping file:
<hibernate-mapping>
<class name="ObjectMap">
<composite-id>
<key-many-to-one name="obj1" column="obj1_item_id" access="field" class="Object1"/>
<key-many-to-one name="obj1" column="obj1_row_id" access="field" class="Object1"/>
<key-many-to-one name="obj2" column="obj2_id" access="field" class="Object2"/>
</composite-id>
</class>
</hibernate-mapping>

Mapping file for Object1:
<hibernate-mapping>
<class name="Object1">
<id name="itemId" column="item_id" access="field"></id>
<property name="rowId" column="row_id" access="field"/>
</class>
</hibernate-mapping>

Mapping file for Object1:
<hibernate-mapping>
<class name="Object2">
<id name="itemId" column="item_id" access="field"></id>
</class>
</hibernate-mapping>

As you can see the table holds two properties from Object1 (this is for auditing purposes). When inserting into this table I would like to put:
Object1.itemId into ObjectMap.obj1_item_id column
Object1.rowId into ObjectMap.obj1_row_id column
Object2.itemId into ObjectMap.obj2_id column

But what actually happens is Object.itemId values get inserted into both ObjectMap.obj1_item_id and ObjectMap.obj1_row_id columns. I guess this makes sense as the Object1 <id> is itemId but is there anyway I can get the Object1.rowId put into ObjectMap.obj1_row_id column? I have looked through the docs but could not see any attributes for the <key-many-to-one> element that may help.

thanks
Steve


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.