Hibernate version:
3.2.6
Mapping documents:
<hibernate-mapping>
<class name="A" table="A">
<id name="id" column="ID" type="long">
<generator class="sequence">
</id>
<set name="AB" table="AB" cascade="all-delete-orphan">
<key column="ID_A"/>
<one-to-many class="AB" />
</set>
</hibernate-mapping>
<hibernate-mapping>
<class name="AB" table="AB">
<composite-id name="id" class="AB$Id">
<key-many-to-one name="entidade" class="A" column="ID_A" />
<key-many-to-one name="entidade" class="B" column="ID_B" />
</composite-id>
<many-to-one name="role" class="Role" column="ID_ROLE" />
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="B" table="B">
<id name="id" column="ID" type="long">
<generator class="sequence">
</id>
<property name="field1" column="field1" type="string" />
<set name="AB" table="AB">
<key column="ID_B"/>
<one-to-many class="AB" />
</set>
</hibernate-mapping>
Name and version of the database you are using:
Oracle10g
I have 2 entities related by an association class, an i want using a criteria with entity A to filter using a property of entity B.
Code:
Criteria select = getSession().createCriteria(A.class);
Criteria ab = select.createCriteria("ab");
Criteria b = ab.createCriteria("id.b");
b.add(Restrictions.eq("field1", "100"));
However the generated sql only does one join, between A and AB, although it references the field1 of table B. Here is the query:
SELECT (...)
FROM a this_ INNER JOIN ab thisab_ ON this_.ID = thisab_.id_a
WHERE servicoonl2_.field1 = ?
The servicoonl2_ wich correspond to the Table B is not declared in the query, so a ORA-00904: invalid identifier error ocurrs.
I don't know if i can actually do a subquery of subquery. I already found a solution using HQL, but i would like to know what i am doing wrong here...
Thanks for you help.