<hibernate-mapping package="com.wepull.hibernate.pojo">
<class name="Card" table="tbl_card">
<id name="cardId" column="pk_card_id">
<generator class="native"/>
</id>
<property name="cardNo" column="card_no"/>
<!-- 需要维护关系的属性,就不是普通属性 -->
<!-- Person和Card沟通的桥梁是外键fk_card_id -->
<one-to-one name="person" property-ref="card"/>
<!-- property-ref="card":通过Person的外键pk_card_id,可以得到pk_person_id -->
</class>
</hibernate-mapping>
<hibernate-mapping package="com.wepull.hibernate.pojo">
<class name="Person" table="tbl_person">
<id name="personId" column="pk_person_id">
<generator class="native"/>
</id>
<property name="personName" column="person_name"/>
<!-- 唯一外键约束 -->
<!-- 此一对一属于多对一的特例 -->
<!-- 先假设多个人共用一张卡,再给fk_card_id添加唯一约束,就变成了一对一关系 -->
<many-to-one name="card" column="fk_card_id" unique="true" cascade="all"/>
</class>
</hibernate-mapping>