Hibernate Tree

Hibernate Tree

 

1.实体类

package com.zhanggaosong.domain;

 

import java.util.Set;

 

public class Tree {

private int deptId; // 部门编号
private String deptName; // 部门名称
private Tree parentDept; // 上级部门
private Set childrenDept; // 下级部门

 

public int getDeptId() {
return deptId;
}

 

public void setDeptId(int deptId) {
this.deptId = deptId;
}

 

public String getDeptName() {
return deptName;
}

 

public void setDeptName(String deptName) {
this.deptName = deptName;
}

 

public Tree getParentDept() {
return parentDept;
}

 

public void setParentDept(Tree parentDept) {
this.parentDept = parentDept;
}

 

public Set getChildrenDept() {
return childrenDept;
}

 

public void setChildrenDept(Set childrenDept) {
this.childrenDept = childrenDept;
}

}

2 .hibernate 映射文件

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

<class name="com.zhanggaosong.domain.Tree" table="tb_Tree" lazy="true">
<id name="deptId">
<generator class="native"/>
</id>

<property name="deptName"/>

<many-to-one name="parentDept" class="com.zhanggaosong.domain.Tree" fetch="select">
<column name="parent_id"/>
</many-to-one>

<set name="childrenDept" inverse="true">
<key>
<column name="parent_id"/>
</key>
<one-to-many class="com.zhanggaosong.domain.Tree" />
</set>

</class>
</hibernate-mapping>

 

posted @ 2013-08-31 13:37  zhgs_cq  阅读(384)  评论(0编辑  收藏  举报