日期:2014-05-18 浏览次数:20700 次
public class User {
private int id;
private String name;
private Vocation vocation;
}
public class Vocation {
private int id;
private String name;
private Vocation parent;
private Set<Vocation> children;
private Set<User> users;
}
<class name="User" table="tt_user">
<id name="id">
<generator class="native"></generator>
</id>
<property name="name"/>
<many-to-one name="vocation" class="Vocation" column="vocationId"></many-to-one>
</class>
<class name="Vocation" table="tt_Vocation">
<id name="id">
<generator class="native"></generator>
</id>
<property name="name"/>
<!-- 多对一 -->
<many-to-one name="parent" class="Vocation" column="vocationId"></many-to-one>
<!-- 一对多 -->
<set name="children">
<key column="vocationId"></key>
<one-to-many class="Vocation"/>
</set>
<set name="users">
<key column="userId"></key><!-- column填写关系的类名+id -->
<one-to-many class="User"/>
</set>
</class>