Hibernate version:Hibernate 3.1.3
Name and version of the database you are using:Firebird 1.5
How can I remove duplicate entries when I'm using fetch?
I've got a class called Parent with 2 child collections and a query like this:
Code:
Criteria criteria = session.createCriteria(Parent.class);
criteria.setFetchMode("children_1", FetchMode.JOIN);
criteria.setFetchMode("children_2", FetchMode.JOIN);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
List<Parent> result = criteria.list();
But I get duplicated entries. I get as Child_1 objects as Child_2, and their number
corresponds to the number of Child_1 objects in the Parent class multiplied by the
number of Child_2 objects also in the Parent Class (cartesian product).
How can I get the Parent objects with the correct number of Child_1 and Child_2 objects?
I've tried mapping the child classes with lazy=false, but I'd like to launch a single query.
Mapping documents:Mapping file Parent:
Code:
<hibernate-mapping>
<class name="Parent" table="Parents">
<id name="id" column="Parent_Id"/>
<set name="children_1" table="Children_1">
<key column="ParentId"/>
<one-to-many class="Child_1"/>
</set>
<set name="children_2" table="Children_2">
<key column="ParentId"/>
<one-to-many class="Child_2"/>
</set>
</class>
</hibernate-mapping>
Mapping file Child1:
Code:
<hibernate-mapping>
<class name="Child_1" table="Children_1">
<id name="id" column="Child_1_Id">
<many-to-one name="parent" class="Parent" column="ParentId"
not-null="true"/>
</class>
</hibernate-mapping>
Mapping file Child2:
Code:
<hibernate-mapping>
<class name="Child_2" table="Children_2">
<id name="id" column="Child_2_Id">
<many-to-one name="parent" class="Parent" column="ParentId"
not-null="true"/>
</class>
</hibernate-mapping>