The mapping below should give you what you are asking for, but, I'm not sure its what you want. The model doesn't seem to create a strong relation ship between Department and Position, which would seem necessary.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="data.User"
table="User"
>
<id
name="userId"
column="userId"
type="java.lang.Long"
>
<generator class="native"/>
</id>
<set
name="departments"
table="User_Pst_Dept"
lazy="false"
cascade="all"
sort="unsorted"
>
<key
column="userId"
>
</key>
<many-to-many
class="data.Department"
column="departmentId"
outer-join="true"
/>
</set>
<set
name="position"
table="User_Pst_Dept"
lazy="false"
cascade="all"
sort="unsorted"
>
<key
column="userId"
>
</key>
<many-to-many
class="data.Position"
column="positionId"
outer-join="true"
/>
</set>
<property
name="userName"
type="java.lang.String"
column="userName"
/>
</class>
</hibernate-mapping>
|