Hi all,
I am having a problem with mapping a bag having a one-to-many relationship with another class. Both the classes have composite-ids with differing keys. Thats is one has a userid and deptid as the composite key and the other has the deptId and processId as the composite Id.
The join is based on DeptID betweeh the two entities. I get the following error:
Quote:
Caused by: net.sf.hibernate.MappingException: Foreign key (V_XXX [DEPT_ID])) must have same number of columns as the reference primary key (V_YYY [USER_ID,DEPT_ID])
Below are the mapping files for the two entities:
1) Here is the UserDepartment mapping based on a view:
Code:
<?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="com.xxx.shared.common.UserDepartment" table="V_XXX">
<composite-id name="UserDepartmentCompositeId"
class="com.xxx.shared.common.UserDepartmentCompositeId">
<key-property column="USER_ID" name="userId"/>
<key-property column="DEPT_ID" name="deptId"/>
</composite-id>
<bag name="processes">
<key column="DEPT_ID"/>
<one-to-many class="com.xxx.shared.common.DepartmentProcess"/>
</bag>
</class>
</hibernate-mapping>
2) Here is the DepartmentProcess mapping based on a view as well:
Code:
<?xml version="1.0"?>
<!--Please note that the ID is given as the first column. Please modify your ID nodes based on the key columns in the table-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.xxx.shared.common.DepartmentProcess" table="V_YYY">
<composite-id name="DepartmentProcessCompositeId"
class="com.xxx.shared.common.DepartmentProcessCompositeId">
<key-property column="DEPT_ID" name="deptId"/>
<key-property column="PROCESS_ID" name="processId"/>
</composite-id>
</class>
</hibernate-mapping>
Any help is greatly appreciated.