-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Duplicate entries when I using Fetch
PostPosted: Tue Sep 19, 2006 1:49 pm 
Newbie

Joined: Wed Aug 30, 2006 3:09 am
Posts: 7
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>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 5:14 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
FAQ


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 20, 2006 1:01 pm 
Newbie

Joined: Wed Aug 30, 2006 3:09 am
Posts: 7
Thank for the help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.