xxx.hbm.xml关系映射模板

===========================模板================================

一对多(Set)
    <set name="">
        <key column=""/>
        <one-to-many class=""/>
    </set>

多对一
    <many-to-one name="" class="" column=""/>

多对多(Set)
    <set name="" table="">
        <key column=""/>
        <many-to-many class="" column=""/>
    </set>

一对一(基于外键的有外键方)
    <many-to-one name="" class="" column="" unique="true"/>

一对一(基于外键的无外键方)
    <one-to-one name="" class="" property-ref=""/>


===========================填空=================================
<!-- privileges属性,表示与Privilege的多对多关系-->
--------1---------------------2---------3-----------------------

1、name属性:填 1
2、class属性:填 2
3、column属性:
    在many-to-one中:写本条配置中的name属性值加Id后缀
    在一对多的<key>中:写对方类的表达此关系的外键名
    在多对多的<key>中:写自己类的名称加Id后缀

    在多对多的many-to-many的column中:写对方类的名称加Id后缀



使用案例

<?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.jxlg.bean">
    
    <class name="Privilege" table="t_privilege">
        <id name="id">
            <generator class="native"/>
        </id>
        <property name="action"/>
        <!--accounts属性,表示与UserAccount的多对多关系-->
        <set name="accounts" table="t_userAccount_privilege">
            <key column="privilegeId"/>
            <many-to-many class="UserAccount" column="userAccountId"/>
        </set>

    </class>
    
</hibernate-mapping>














评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值