Hibernate one to many using something other than a

2019-06-18 23:54发布

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条回答
欢心
2楼-- · 2019-06-19 00:26

Solved with

<set name="someSet" table="B" lazy="false">
    <key column="B_not_primary" property-ref="secondary_column" />
    <one-to-many class="BClass" />
</set>
查看更多
登录 后发表回答