<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class
name="example.Element"
table="T_ELEMENT"
dynamic-update="true"
dynamic-insert="true"
lazy="false">
<id
name="listId"
type="java.lang.Long"
column="LIST_ID">
<generator class="sequence">
<param name="sequence">S_ELEMENT_ID</param>
</generator>
</id>
<property
name="name"
type="java.lang.String"
column="NAME"
length="50"/>
<!--
Node类是Element类的子类,这是遵循table per subclass的继承映射方法
-->
<joined-subclass name="example.Node"
table="T_NODE" lazy="false">
<key column="LIST_ID" />
<!--
Node类的父节点是自身类型
-->
<many-to-one
name="parentNode"<!--映射类中的父节点字段-->
cascade="none"
outer-join="false">
<column
name="PARENT_ID"<!--指向父节点的外键-->
not-null="false"/>
</many-to-one>
<!--
Node类的子节点也是自身类型,
-->
<set
name="childNodes"<!--映射类中的所有子节点字段-->
cascade="all-delete-orphan"
inverse="true"
lazy="true"
batch-size="10"<!--这个属性可以提高性能,若没有设置,则hibernate一次只会取一条-->
>
<key column="PARENT_ID"/>
<one-to-many class="example.Node"/>
</set>
</joined-subclass>
</class>
</hibernate-mapping>