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一一对应

 

posted @ 2017-03-18 23:11  洞玄巅峰  阅读(133)  评论(0编辑  收藏  举报