-->
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: exotic mapping
PostPosted: Wed Aug 04, 2010 1:23 pm 
Newbie

Joined: Fri Oct 14, 2005 4:42 pm
Posts: 15
How do I map a 1-1 association between two classes, where there is one table per class, and neither table has a foreign-key to the other?

Table A has fields mpk, ms, prj, nm, vl, and a primary key of mpk.

Table B has fields la, ms, prj, org, ts with a composite key of (la, ms).

In both tables, combination (ms, prj) is unique

Now I want corresponding classes CA and CB to have mapped assciations to one another where A.ms = B.ms and A.prj = B.prj.

I tried this:

<class name="CA" table="A">
...
<one-to-many name="myB" property-ref="myA" />
</class>

<class name="CB" table="B">
...
<many-to-one name="myA" formula="(SELECT mpk from A where A.ms = ms and A.prj = prj)" />
</class>

When attempting to access A.myB, the resulting SQL to fetch the row of B is invalid, with the formula appearing as a selected expression and in the where clause with $PlaceHolder$ aliases:

select B0_la as FK1_0_ , B0_ms as MS2_169_0_, B0_prj as FK2_169_0_, B0_org as FK3_169_0_, B0_ts as TS5_169_0, (SELECT mpk from A where A.ms = B0_.ms and A.prj = B0_.prj) as formula27_0_ from B B0_ where B0_(SELECT mpk from A where A.ms = $PlaceHolder$.ms and A.prj = $PlaceHolder$.prj)=?

The bind parameter is set to the A.mpk whose myB property is being accessed.

What I really want is:

select B0_la as FK1_0_ , B0_ms as MS2_169_0_, B0_prj as FK2_169_0_, B0_org as FK3_169_0_, B0_ts as TS5_169_0 from B B0_ where (SELECT mpk from A where A.ms = B0_.ms and A.prj = B0_.prj)=?

Can anyone help?


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.