Hibernate One-to-One Mapping Using Composite Key and Non-primary Property
So here is my problem. I have these two tables which map fine by themselves. There are some additional fields which I removed because they are ir开发者_Go百科relevant. I need a one-to-one mapping between Item and ItemAdminScrtyGrp for the owner of an item. I have included the SQL I would use to get the owner of an item. Changing the database schema is not an option. Any ideas how I can combine parts of a composite key and a non-primary property for the mapping?
Hibernate Mapping
<hibernate-mapping>
<class name="Item">
<composite-id class="ItemKey" name="itemKey" >
<key-property name="itemId" column="ITEM_ID" />
<key-property name="revision" column="RVSN_ID" />
</composite-id>
</class>
<class name="ItemAdminScrtyGrp">
<composite-id name="key" class="ItemAdminScrtyGrpKey" >
<key-property name="securityProfileCode" column="SCRTY_PROF_CD" />
<key-property name="itemId" column="ITEM_ID" />
<key-property name="revision" column="RVSN_ID" />
</composite-id>
<property name="securityLevelCode" column="SCRTY_LVL_TYP_CD" />
<property name="ownerFlag" column="OWNR_FLG"/>
</class>
</hibernate-mapping>
SQL
select SCRTY_PROF_CD from ItemAdminScrtyGrp grp
join Item
on grp.ITEM_ID = Item.ITEM_ID and
grp.RVSN_ID = Item.RVSN_ID and
grp.OWNR_FLG = 'y'
where Item.ITEM_ID = 'abc' and Item.RVSN_ID = '123';
Thanks for any help you can provide.
There seems to be a defect on such mappings. See See https://hibernate.atlassian.net/browse/HHH-4939
精彩评论