-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: problem with mapping a one-to-many with composite ids
PostPosted: Mon Dec 15, 2003 6:35 pm 
Newbie

Joined: Tue Oct 07, 2003 9:43 am
Posts: 16
Location: Chicago
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.


Top
 Profile  
 
 Post subject: Re: problem with mapping a one-to-many with composite ids
PostPosted: Mon Dec 15, 2003 11:52 pm 
Beginner
Beginner

Joined: Thu Sep 25, 2003 10:30 am
Posts: 23
Location: india
Hi,
I think it should be mapped in following way
<bag name="" cascade="all" inverse="true" lazy="true">
<key column="something">
<column name=""/>
<column name=""/>
</key>
<one-to-many class="" />
</bag>


Top
 Profile  
 
 Post subject: Re: problem with mapping a one-to-many with composite ids
PostPosted: Tue Dec 16, 2003 12:40 am 
Beginner
Beginner

Joined: Thu Sep 25, 2003 10:30 am
Posts: 23
Location: india
Hi,
Sorry about the previous post. Here is the actual example


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="org.presci.bag.Address" table="address">
        <id name="id">
            <generator class="identity"/>
        </id>

        <property name="address1"/>
        <property name="address2"/>
        <many-to-one name="employee" class="org.presci.bag.Employee">
           <column name="emp_id"/>
           <column name="emp_no"/>
        </many-to-one>
        </class>

</hibernate-mapping>



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="org.presci.bag.Employee" table="employee">
       <composite-id class="org.presci.bag.EmployeeIdentifier">
          <key-property column="emp_id" name="employeeid"/>
          <key-property column="emp_no" name="employeeno"/>
       </composite-id>
        <property name="fname"/>
        <property name="lname"/>
    </class>

</hibernate-mapping>
<!-- parsed in 10ms -->



[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.