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.  [ 2 posts ] 
Author Message
 Post subject: mapping problem: non-primary key for optional join
PostPosted: Mon Feb 01, 2010 1:28 pm 
Newbie

Joined: Mon Feb 01, 2010 1:04 pm
Posts: 6
I just started using Hibernate 3.2.4.sp1 (coming with jboss-4.2.3.GA) trying to map a legacy DB.
I have a problem mapping a non-primary key for an optional join.

Entity Tm has Primary key id, but also a composite business key (mpk1, mpk2), wrapped via class TmPK
There is a one-to-optional-one relation to a second table Td, whose columns are mapped into Tm. But the primary key of Td is not Tm.id, but the composite business key

Code:
class Tm {
Integer id;
TmPK tmPK;
String something;
String other; //from Td
}


Existing queries look something like that:
Code:
SELECT Tm.id, Tm.mpk1, Tm.mpk2, Tm.something, Td.other
FROM Tm
LEFT JOIN Td ON Tm.mpk1 = Td.dpk1 AND tm.mpk2 = Td.dpk2
WHERE Tm.id = ?


Mapping:
Code:
<class name="Tm">
<id name="id"/>
<component name="tmPK" unique="true">
  <property name="mpk1">
  <property name="mpk2">
</component>
<property name="something"/>
<join table="Td" optional="true">
  <key property-ref="tmPK" unique="true" not-null="true">
   <column name="dpk1">
   <column name="dpk2">
  </key>
  <property name="other"/>
</join>


even though giving property-ref="tmPK", I get the following Exception:
org.hibernate.MappingException: Foreign key (tmPK:Td [dpk1,dpk2])) must have same number of columns as the referenced primary key (Tm [id])

tried with foreign-key="tmPK", but the same.

Could anybody shed some light on how to map it properly?

thx, Jürgen


Top
 Profile  
 
 Post subject: Re: mapping problem: non-primary key for optional join
PostPosted: Wed Feb 10, 2010 9:37 am 
Newbie

Joined: Mon Feb 01, 2010 1:04 pm
Posts: 6
to answer my own post:
http://opensource.atlassian.com/project ... se/HHH-551
seems as if <join> with <property-ref> is still not supported


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