Hibernate 一对一"连接表"双向关联
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personId">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="age"/>
<join table="join" optional="true">
<key column="personId" unique="true"/>
<many-to-one name="address" column="addressId" not-null="true" unique="true"/>
</join>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressId">
<generator class="identity"/>
</id>
<property name="addressDetail"/>
<join table="join" optional="true" inverse="true">
<key column="addressId" unique="true"/>
<many-to-one name="person" column="personId" not-null="true" unique="true"/>
</join>
</class>
</hibernate-mapping>
Hibernate 一对一"主键"双向关联
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personId">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="age"/>
<one-to-one name="address" cascade="all"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressId">
<generator class="foreign">
<param name="property">person</param>
</generator>
</id>
<property name="addressDetail"/>
<!--表明主键由关联属性生成-->
<one-to-one name="person" cascade="all" constrained="true"/>
</class>
</hibernate-mapping>
Hibernate 一对一"外键"双向关联
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personId">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="age"/>
<one-to-one name="address" cascade="all" property-ref="person"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressId">
<generator class="identity"/>
</id>
<property name="addressDetail"/>
<many-to-one name="person" unique="true"/>
</class>
</hibernate-mapping>
Hibernate 多对多单向关联
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personId">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="age"/>
<!--映射集合属性,join是连接表表名-->
<set name="addresses" table="join" >
<key column="personId"/>
<many-to-many column="addressId" class="cn.dy.Address"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressId">
<generator class="identity"/>
</id>
<property name="addressDetail"/>
</class>
</hibernate-mapping>
Hibernate 多对一"连接表"单向关联
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personId">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="age"/>
<join table="join">
<key column="personId"/>
<many-to-one name="address"/>
</join>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressId">
<generator class="identity"/>
</id>
<property name="addressDetail"/>
</class>
</hibernate-mapping>
Hibernate 多对一外键单向关联
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personId">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="age"/>
<many-to-one name="address" column="addressId"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressId">
<generator class="identity"/>
</id>
<property name="addressDetail"/>
</class>
</hibernate-mapping>
Hibernate 一对多连接表单向关联
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personId">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="age"/>
<set name="addresses" table="join" >
<key column="personId"/>
<many-to-many column="addressId" unique="true" class="cn.dy.Address"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressId">
<generator class="identity"/>
</id>
<property name="addressDetail"/>
</class>
</hibernate-mapping>
Hibernate 一对一主键单向关联
<id name="personId">
<generator class="foreign">
<param name="property">address</param>
</generator>
</id>
<one-to-one name="address" constrained="true"/>
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personId" column="presonid">
<generator class="foreign">
<param name="property">address</param>
</generator>
</id>
<property name="name"/>
<property name="age"/>
<one-to-one name="address" constrained="true"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressId">
<generator class="identity"/>
</id>
<property name="addressDetail"/>
</class>
</hibernate-mapping>
Hibernate 一对一外键单向关联
<many-to-one name="address" column="addressId" unique="true"/>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressId">
<generator class="identity"/>
</id>
<property name="addressDetail"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personId">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="age"/>
<many-to-one name="address" column="addressId" unique="true"/>
</class>
</hibernate-mapping>
Hibernate 一对多外键单向关联
<set name="addresses" table="ADDRESS" cascade="all" >
<key column="personid"/>
<one-to-many class="cn.dy..Address"/>
</set>
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personid">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="age"/>
<set name="addresses" table="ADDRESS" cascade="all" >
<key column="personid"/>
<one-to-many class="cn.dy..Address"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressid">
<generator class="identity"/>
</id>
<property name="addressdetail"/>
</class>
</hibernate-mapping>
Hibernate 一对一连接表单向关联
<join table="join">
<key column="personid"/>
<many-to-one name="address" unique="true"/>
</join>
<hibernate-mapping>
<class name="cn.dy.Person" table="PERSON">
<id name="personid">
<generator class="identity"/>
</id>
<property name="name"/>
<property name="age"/>
<join table="join">
<key column="personid"/>
<many-to-one name="address" unique="true"/>
</join>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="cn.dy.Address" table="ADDRESS">
<id name="addressid">
<generator class="identity"/>
</id>
<property name="addressdetail"/>
</class>
</hibernate-mapping>