hibernate 關係對應檔配置

來源:互聯網
上載者:User

標籤:desc   net   配置   code   多對一   ble   source   set   ber   

<!--Department.hbm.xml users屬性,本類與User的一對多 --><set name="users"><key column="departmentId"></key><one-to-many class="User" /></set><!-- parent屬性,本類與Department(上級)的多對一 --><many-to-one name="parent" class="Department" column="parentId"></many-to-one><!-- children屬性,本類與Department(下級)的一對多 --><set name="children" cascade="delete">  <!-- 串聯刪除 --><key column="parentId"></key><one-to-many class="Department" /></set>

User.hbm.xml

<?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="cn.itcast.oa.domain"><class name="User" table="qust_user"><id name="id">            <generator class="native"/></id><property name="loginName" /><property name="password" /><property name="name" /><property name="gender" /><property name="phoneNumber" /><property name="email" /><property name="description" /><!-- department屬性。本類與Department的多對一 --><many-to-one name="department" class="Department" column="departmentId"></many-to-one><!-- roles屬性,本類與Role的多對多 --><set name="roles" table="itcast_user_role"><key column="userId"></key><many-to-many class="Role" column="roleId"></many-to-many></set></class></hibernate-mapping>
Role.hbm.xml

<?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="cn.itcast.oa.domain"><class name="User" table="qust_user"><id name="id">            <generator class="native"/></id><property name="loginName" /><property name="password" /><property name="name" /><property name="gender" /><property name="phoneNumber" /><property name="email" /><property name="description" /><!-- department屬性。本類與Department的多對一 --><many-to-one name="department" class="Department" column="departmentId"></many-to-one><!-- roles屬性,本類與Role的多對多 --><set name="roles" table="itcast_user_role"><key column="userId"></key><many-to-many class="Role" column="roleId"></many-to-many></set></class></hibernate-mapping>
所遵循的規律:
<!-- users屬性,本類與User的一對多 -->
格式:?屬性,本類與?的?
?1 屬性名稱
?2 關聯對類型
?3 關係


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

hibernate 關係對應檔配置

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.