一对一,则有主对象和从对象之区别
若无主对象,则从对象亦无存在之意义。
主对象为person
从对象为idcard
<hibernate-mapping package="cn.itcast.hibernate.domain"> <class name="Person"> <id name="id"> <generator class="native" /> </id> <property name="name" /> <one-to-one name="idCard"/> </class> </hibernate-mapping>
<hibernate-mapping package="cn.itcast.hibernate.domain"> <class name="IdCard" table="id_card"> <id name="id"> <generator class="foreign"> <param name="property">person</param> </generator> </id> <property name="name"/> <one-to-one name="person" constrained = "true"/> </class> </hibernate-mapping>
constrained = "true"是约束,即为加上外键引用。
时间: 2024-10-01 15:50:52