Hibernate version: 3.1.1
I have a mapping problem with a legacy db where there are two tables to be represented by one class.
It's a one-to-one relationship and the 2 tables were related as a parent-child where my A_LEFT is the child with the foreign key. Unfortunately Hibernate seems to want A_LEFT to be the parent and cannot handle this.
This is the SQL I want:
Code:
select * from A_LEFT A left outer join B_RIGHT B on A.foreignKey = B.id
because B sometimes has no data.
My 1st mapping attempt failed:
Code:
<class table="A_LEFT">
<id column="id"/>
<property name="fk" column="A_FK"/>
<join table="B_RIGHT" optional="true">
<key column="id" />
</join>
</class>
because Hibernate expects B to relate to A's primary key. So I looked further and found the <properties> and <property-ref> syntax, which I set up so:
Code:
<class table="A_LEFT">
<id column="id"/>
<properties name="aForeignKey">
<property name="fk" column="A_FK"/>
</properties>
<join table="B_RIGHT" optional="true">
<key column="id" property-ref="aForeignKey"/>
</join>
</class>
But this failed too, inexplicably. The SQL that it pumps out just completely ignores my <property-ref>, i.e.
Code:
select * from A_LEFT A left outer join B_RIGHT B on A.ID = B.ID
instead of
Code:
select * from A_LEFT A left outer join B_RIGHT B on A.A_FK = B.ID
Why does Hibernate ignore the property-ref on my join key? Could it be a bug? Is there some other approach?
Thanks