使用除主键以外的东西休眠一对多 [英] Hibernate one to many using something other than a primary key

查看:108
本文介绍了使用除主键以外的东西休眠一对多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类 A ,它有一组 B 的s。但是,这两个对象通过不是主键的字段链接。

I have a class A that has a set of B's. However, these two objects are linked by fields that are NOT the primary key.

对于 B ,我可以使用< key column> ,但是如何指定连接应该位于 A secondary_column ?不是 A table_primary_key_id

For B, I can use <key column>, but how do I specify that the join should be in A.secondary_column? Not A.table_primary_key_id ?

<class table="a">
    <id column="table_primary_key_id">
    </id>
    <property column="secondary_column" />

    <set table="B" lazy="false" >
        <key column="B_not_primary" />
        <one-to-many class="BClass" />
    </set>
</class>    


推荐答案

b $ b

<set name="someSet" table="B" lazy="false">
    <key column="B_not_primary" property-ref="secondary_column" />
    <one-to-many class="BClass" />
</set>

这篇关于使用除主键以外的东西休眠一对多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆