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?
|