码迷,mamicode.com
首页 > 系统相关 > 详细

hibernate 关系映射文件配置

时间:2014-05-02 22:06:25      阅读:444      评论:0      收藏:0      [点我收藏+]

标签:hibernate

<!--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>



hibernate 关系映射文件配置,布布扣,bubuko.com

hibernate 关系映射文件配置

标签:hibernate

原文地址:http://blog.csdn.net/fangchao3652/article/details/24837095

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!