<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.entity">
<class name="Husband">
<id name="hid">
<generator class="native"></generator>
</id>
<property name="name" />
<many-to-one name="wife" column="wid" unique="true"></many-to-one>
</class>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.entity">
<class name="Husband">
<id name="hid">
<generator class="native"></generator>
</id>
<property name="name" />
<many-to-one name="wife" column="wid" unique="true"></many-to-one>
</class>
</hibernate-mapping>
重点是:在many-to-one中只要加入 unique="true" 就是one-to-one的关系映射