-->
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.  [ 1 post ] 
Author Message
 Post subject: one-tomany mapping with child having composite key
PostPosted: Fri Jul 18, 2008 6:24 pm 
Newbie

Joined: Fri Jul 18, 2008 5:55 pm
Posts: 1
I have a parent table Employee and a child table Employee_Address

Primary key of Parent empId
Composite key of child empAddressId and accountNumber


Parent table has accountNumber as a column
Child table has empId as a column


I am unable to set one-tomany association in this scenario

Here is my Employee (PARENT) mapping file

<hibernate-mapping>
<class name="Employee" table="EMPLOYEE">
<id name="empId" type="long">
<column name="EMP_ID" precision="15" scale="0" />
<generator class="assigned" />
</id>
<property name="acctNo" type="string">
<column name="ACCT_NO" length="5" not-null="true" />
</property>


<set name="empAddresses" inverse="true" lazy="true">
<key>
<column name="empId"/>

</key>
<one-to-many class="EmpAddress" />
</set>

</class>
</hibernate-mapping>


Java BEAn for Employee is very standard with all the getters/setters


EmployeeAddress (CHILD) mapping file:

<hibernate-mapping>
<class name="EmpAddress" table="POL_INT_ADDRESS">


<composite-id name="id" class="EmpAddressKey">
<key-property name="addressId"/>
<key-property name="acctNo"/>
<key-property name="empId"/>
</composite-id>


<many-to-one name="emp" class="Employee" insert="false" update="false" fetch="join">
<column name="empId"/>
</many-to-one>
<property name="xval" type="long">
<column name="X_VAL" precision="15" scale="0" not-null="true" />
</property>
<property name="yVal" type="int">
<column name="Y_VAL" not-null="true" />
</property>
</class>
</hibernate-mapping>


Java code for the composite key EmpAddresskey
public class EmpAddressKey implements Serializable{


private String acctNo;
private long empAddressId;
private long empId;

public EmpAddressKey(long empAddressId, String acctNo, long empId) {
///intialize parametrs
}

//getters/setters for empAddressId, empId, acctNo

//equals and has code methods also implemented

}


When I run Session.load(Employee)...I get the result set for Employee (PARENT ) table but the collections size for EmpAddress is Zero.


Can someone point me in right direction. Anything wrong with the mapping???
I get Error:could not load an entity: [Employee#1234]


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

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.