使用复合键和非主属性的 Hibernate 一对一映射
所以这是我的问题。我有这两个表,它们本身映射得很好。我删除了一些其他字段,因为它们不相关。我需要项目所有者的 Item 和 ItemAdminScrtyGrp 之间的一对一映射。我已经包含了用于获取项目所有者的 SQL。更改数据库架构不是一个选项。有什么想法可以将复合键的一部分和非主要属性组合起来进行映射吗?
Hibernate 映射
<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';
感谢您提供的任何帮助。
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 irrelevant. 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种映射似乎存在缺陷。看
请参阅https://hibernate.atlassian.net/browse/HHH-4939
There seems to be a defect on such mappings. See
See https://hibernate.atlassian.net/browse/HHH-4939