下面是以主键关联的Customer和Certificate的映射文件:
● Customer.hbm.xml:
<hibernate-mapping> <class name="hibernate.Customer" table="customer" schema="dbo" catalog="test"> <id name="id" type="java.lang.Long"> <column name="id" /> <generator class="uuid.hex" /> </id> <!--映射对应的身份对象--> <one-to-one name="Certificate" class="hibernate.Certificate"
update="true" insert="true" fetch="select" cascade="all"/> <property name="name" type="java.lang.String"> <column name="name" length="50" not-null="true" /> </property> </class> </hibernate-mapping>
<hibernate-mapping> <class name="hibernate.Certificate" table="certificate" schema="dbo" catalog="test"> <id name="id" type="java.lang.Long"> <column name="id" /> <!—引用Customer的主键作为Certificate的主键和外键--> <generator class="foreign" /> <param name="property">Customer</param> </generator> </id> <property name="information" type="java.lang.String"> <column name="information" length="50" not-null="true" /> </property> <one-to-one name="Customer" class="hibernate.Customer" constrained="true"<!—表示Certificate引用了Customer主键作外键--> </class> </hibernate-mapping>
更多内容请看PCdog.com--Hibernate高级特性 Hibernate相关文章专题

