-->
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.  [ 4 posts ] 
Author Message
 Post subject: composite id with many-to-one
PostPosted: Wed Jun 29, 2005 12:12 pm 
Beginner
Beginner

Joined: Sun Aug 22, 2004 5:32 pm
Posts: 40
Is it possible to use a many-to-one mapping with a composite id?

Here is my code:
<many-to-one name="caseVO" column="Case_Id" class="CaseVO" not-null="true"/>

The CaseVO class has a composite id defined as follows:

<composite-id name="id" class="CaseNumberVO">
<key-property name="caseSequenceNumber" column="Case_Seq_Nbr" type="int"/>
<key-property name="agencyStateCode" column="Age_St_Cd" type="string" length="4"/>
</composite-id>

I get the following error:
Foreign key (Case_Id) must have same number of columns as the referenced primary key (case)

What is the correct way to implement this if it is possible?

Thanks. :)

_________________
Scott
www.HikeHaven.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 12:33 pm 
Newbie

Joined: Thu Jun 16, 2005 2:51 am
Posts: 12
You will need to map 2 colums with 2 colums

for example:

<many-to-one name="abteilung" class="de.test.pps.VoAbteilung" >
<column name="mandant"></column>
<column name="abteilungsnummer"></column>
</many-to-one>

regards


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 12:38 pm 
Beginner
Beginner

Joined: Sun Aug 22, 2004 5:32 pm
Posts: 40
maxwell wrote:
You will need to map 2 colums with 2 colums

for example:

<many-to-one name="abteilung" class="de.test.pps.VoAbteilung" >
<column name="mandant"></column>
<column name="abteilungsnummer"></column>
</many-to-one>

regards


Works great!!! Thanks!!!

_________________
Scott
www.HikeHaven.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 01, 2005 1:28 pm 
Beginner
Beginner

Joined: Sun Aug 22, 2004 5:32 pm
Posts: 40
How can I create a set for a one-to-many in a different object, which uses this primary key?

I tried this, but got an error trying to parse.

Class A (SubjectVO)
<man-to-one name="caseVO" class="CaseVO" not-null="true">
<column name="Case_Sequence_Nbr"/>
<column name="Agency_State_Cd"/>
</many-to-one>

Class B (CaseVO)
<set name="subjects">
<key column="case_id"/>
<one-to-many class="CaseVO">
<column name="Case_Sequence_Nbr"/>
<column name="Agency_State_Cd"/>
</one-to-many>
</set>

I don't think I implemented this correctly........

Also, how can I find out what the id of a newly created record is?

Thanks.

_________________
Scott
www.HikeHaven.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.