Hibernate 一对一(基于唯一外键的关联)

主表 hbm.xml中 使用<one-to-one>

从表hbm.xml中使用<many-to-one> 并指定unique=true

people.hbm.xml:

<one-to-one name="passport" cascade="all" property-ref="people">

passport.hbm.xml:

<many-to-one name="people">

<column name="people_id" unique=true></column>

</many-to-one>

pepole的主键与passport表中people_id一一对应

原文地址:https://www.cnblogs.com/coderdxj/p/6576674.html