<hibernate-mapping>
<class table="t_Department" name="com.oa.model.Department">
<id name="id" >
<generator class="native"/>
</id>
<property name="name" />
<property name="description" />
<!-- user, wo对user的一对多关联 -->
<set name="users" >
<key column="departmentId" ></key>
<one-to-many class="com.oa.model.User" />
</set>
<!-- department(子)对department(父)的多对一关联 -->
<many-to-one name="parent" class="com.oa.model.Department" column="parentId" />
<!-- department(父)对department(子)的一对多关联 -->
<set name="children" cascade="delete" lazy="false" >
<key column="parentId"/>
<one-to-many class="com.oa.model.Department" />
</set>
</class>
</hibernate-mapping>
注:这个是以前做的,native主键生成方式会根据不同的底层数据库自动选择不同的主键生成方式,
如Identity、Sequence、Hilo,这样Hibernate会根据底层数据库采用不同的映射方式,更加便于程序移植 |