天天看點

一對一映射,外鍵。

在設計pojo時,這兩個類都有一個對方類的對象做屬性。
<one-to-one>這一方,首先申明那個關聯的屬性,property-ref怎麼來找這個表的主鍵,是通過關聯屬性中的屬性來獲得。
再說明級聯。 <many-to-one> 說明關聯屬性,還有這個表得增加一個字段column=“fid”,unique=“true”           

 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.liucy.ebank.biz.entity "> <class name="Account" table="t_account"> <id name="oid" column="OID"> <generator class="seqhilo"> </generator> </id> <property name="actNo" column="ACTNO" not-null="true" unique="true"></property> <property name="bal" column="BALANCE" not-null="true"></property> <one-to-one name="user" property-ref="act" cascade="save-update"></one-to-one> </class> </hibernate-mapping> <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.liucy.ebank.biz.entity"> <class name="User" table="t_user"> <id name="oid" column="OID"> <generator class="seqhilo"> </generator> </id> <property name="uid" column="USERID" unique="true" not-null="true"></property> <property name="name" column="NAME"tor> not-null="true"></property> <many-to-one name="act" column="fid" unique="true" cascade="all"></many-to-one> </class> </hibernate-mapping>