I am having an issue when trying to map a (one-to-many) association.
The child object is based off of two tables (using a join), and the parent object needs to filter the results (using a where clause on the set) using two columns, one from each of the tables that the child object is based on.
Hibernate version: 3.1.2
Mapping documents:
Mapping Document 1:
<hibernate-mapping>
<class name="A" table="A">
<id name="id" type="java.lang.Integer">
<column name="A_NUM"/>
</id>
<property name="aProperty1">
<column name="A_FIELD_1" not-null="true"/>
</property>
<set name="setOfBs" where="B1_FIELD_1 = 0 AND B2_FIELD_1 = 1">
<key column="B_A_NUM"/>
<one-to-many class="B" />
</set>
</class>
</hibernate-mapping>
Mapping Document 2:
<hibernate-mapping>
<class name="B" table="B1">
<id name="id" type="java.lang.Integer">
<column name="B1_NUM"/>
</id>
<property name="b1Property1">
<column name="B1_FIELD_1" not-null="true"/>
</property>
<join table="B2">
<key column="B2_B1_NUM" />
<property name="b2Property1">
<column name="B2_FIELD_1" />
</property>
</join>
</class>
</hibernate-mapping>
Name and version of the database you are using: Oracle 8i
The generated SQL (show_sql=true):
where b0_.B1_NUM=b0_1_.B2_B1_NUM and b0_.B1_FIELD_1 = 0 AND b0_.B2_FIELD_1 = 1
As you can see from the extracted where clause, both fields in the where (B1_FIELD_1 and B2_FIELD_1) are being prefixed with the generated alias for the root table B1. the where should read:
where b0_.B1_NUM=b0_1_.B2_B1_NUM and b0_1_.B1_FIELD_1 = 0 AND b0_.B2_FIELD_1 = 1
Any help is much appreciated!
Thanks!
|