I met such problem as below. If anyone has idea about that, please do me a favor.
I need to mapping a one-to-many relationship in hbm file to join two tables(say table_A and table_B) together. The expected class heirachy like: class TableA { .... List<TableB> tableb; }
But the join is not based on the primary key of the table_A, but a composite non-primary key (column a2 and a3, the composite key is also an unique key). It is an existing business logic, so I can not change the join condition. So the join condition will be like: table_A.a2 = table_B.b2 and table_A.a3 = table_B.b3
I know with composite primary key, one-to-many mapping could be (suppose table_B still use column b2 and b3)
<bag name=" tableb" > <key> <colunm name="b2" > < colunm name="b3"> </key> <one-to-many class="TableB"> </bag>
For single non-primary key(suppose talbe_A a2 column), one-to-many mapping could be (suppose table_B uses column b2) <bag name=" tableb" > <key column name = "b2" property-ref="a2"/> <one-to-many class="TableB"> </bag>
Now, my question comes. For the composite case, I need use property-ref to specify the non-primary keys, but I can't find anywhere to hold it: <key>, <column> or <one-to-many>section.
Anyone has any idea about that?
Thanks a lot.
|