public class User {
private int id;
private String username;
private IdCard idCard;
}
public class IdCard {
private int id;
private String cardNO;
private User user;
}
<class name="IdCard">
<id name="id" >
<column name="t_id" />
<generator class="native"></generator>
</id>
<property name="cardNO" >
<column name="cardNO" length="50" />
</property>
<one-to-one name="user" property-ref="idCard"/>
</class>
<class name="User" >
<id name="id" >
<column name="t_id" />
<generator class="native"/>
</id>
<property name="username"/>
<many-to-one name="idCard" unique="true"> </many-to-one>
一对一外键关联映射双向 就是在一对一外键单向关联映射的基础上,在idCard的一端加了对User的引用,在hbm.xml文件中 <one-to-one name="user" property-ref="idCard"/>
private int id;
private String username;
private IdCard idCard;
}
public class IdCard {
private int id;
private String cardNO;
private User user;
}
<class name="IdCard">
<id name="id" >
<column name="t_id" />
<generator class="native"></generator>
</id>
<property name="cardNO" >
<column name="cardNO" length="50" />
</property>
<one-to-one name="user" property-ref="idCard"/>
</class>
<class name="User" >
<id name="id" >
<column name="t_id" />
<generator class="native"/>
</id>
<property name="username"/>
<many-to-one name="idCard" unique="true"> </many-to-one>
一对一外键关联映射双向 就是在一对一外键单向关联映射的基础上,在idCard的一端加了对User的引用,在hbm.xml文件中 <one-to-one name="user" property-ref="idCard"/>