Hibernate 的多对一关联中,一般子表的外键都是关联到主表的主键,如果该外键不是关联到主表的主键,可使用 property-ref 属性,如:
Student 和 Dept 是多对一的关联, Student 表中有 dept_id 字段作为外键,关联到 Dept 表的字段 dept_no ( 非主键 ) , Sudent 和 Dept 实体的配置可按如下:
<many-to-one name="dept" class="Dept" property-ref="dept_no" >
<column name="dept_id" />
</many-to-one>
本文详细解释了在Hibernate的多对一关联中,当子表的外键不是关联到主表的主键时,如何通过property-ref属性进行配置。以Student和Dept实体为例,展示了如何正确地使用property-ref来建立关联。
783

被折叠的 条评论
为什么被折叠?



