<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="cn.itcast.domain.SysUser" table="sys_user">
<id name="userId" column="user_id">
<generator class="native"></generator>
</id>
<property name="userName" column="user_name"></property>
<property name="userMemo" column="user_memo"></property>
<!--
set標籤:映射集合屬性
name屬性:指定集合屬性名字
table屬性:指定中間表名
-->
<set name="roles" table="user_role" cascade="delete">
<key column="user_id"></key>
<!--
many-to-many:指定當前實體與對方是多對多的關係
column屬性:指定對方在中間表裏外鍵列的名字
-->
<many-to-many class="cn.itcast.domain.SysRole" column="role_id"></many-to-many>
</set>
</class>
</hibernate-mapping>app
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="cn.itcast.domain.SysRole" table="sys_role">
<id name="roleId" column="role_id">
<generator class="native"></generator>
</id>
<property name="roleName" column="role_name"></property>
<property name="roleMemo" column="role_memo"></property>
<set name="users" table="user_role" inverse="true" cascade="delete">
<key column="role_id"></key>
<many-to-many class="cn.itcast.domain.SysUser" column="user_id"></many-to-many>
</set>
</class>
</hibernate-mapping>dom