加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xxx.hbm.xml关系映射模板

发布时间:2020-12-16 05:04:12 所属栏目:百科 来源:网络整理
导读:===========================模板================================ 一对多(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
===========================模板================================

一对多(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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读