Hibernate one to many using something other than a primary key

好久不见. 提交于 2019-12-23 09:42:19

问题


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.

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>    

回答1:


Solved with

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


来源:https://stackoverflow.com/questions/1241026/hibernate-one-to-many-using-something-other-than-a-primary-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!