Hi
I have two tables user and role and an intermediate table user_role. Here is my user.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="User" table="USERS">
<id name="id" column="USER_ID">
<generator class="assigned"/>
</id>
<property name="lastName" column="LAST_NAME"/>
<property name="firstName" column="FIRST_NAME"/>
<property name="password" column="PASSWORD"/>
<property name="email" column="EMAIL"/>
<set name="roleAliases" table="USER_ROLE">
<key>
<column name="USER_ID" not-null="true"/>
</key>
<many-to-many class="RoleAlias">
<column name="ROLE_ALIAS_ID" not-null="true"/>
</many-to-many>
</set>
<many-to-one name="dept" column="DEPT_ID"/>
<set name="divs" table="USER_DIVISION">
<key>
<column name="USER_ID" not-null="true"/>
</key>
<many-to-many class="Division">
<column name="DIV_ID" not-null="true"/>
</many-to-many>
</set>
<property name="active" column="ACTIVE"/>
<property name="midName" column="MIDDLE_NAME"/>
</class>
</hibernate-mapping>
The user details are retrieved properly. But when I try to update an user, instead of updating the user_role table, it deletes the user data and inserts a new record. My user-role table can have multiple records with the same user id. So if I update the user, it deletes all the user records from the table. How do I force it to update the user_role table instead of delete/insert?
Thanks
|