-->
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: Parent/Child mapping returning duplicate parent objects
PostPosted: Thu Dec 16, 2004 12:55 pm 
Newbie

Joined: Thu Dec 02, 2004 3:51 pm
Posts: 8
Hibernate version:
2.1.7
Mapping documents:
<class name="com.argus.issueTracker.domain.vo.Project" table="projects">
<id name="projectId" column="project_id" type="integer">
<generator class="increment"/>
</id>
<property name="projectName" column="project_name" type="string"/>
<property name="creationDate" column="creation_date" type="timestamp"/>
<property name="createdBy" column="created_by" type="integer"/>
<property name="status" column="status" type="string"/>
<property name="parentProjectId" column="parent_id" type="integer"/>
<bag name="threads" order-by="opened desc" outer-join="true" cascade="delete" inverse="true">
<key column="project_id"/>
<one-to-many class="com.argus.issueTracker.domain.vo.Thread"/>
</bag>
<many-to-one name="parentProject" insert="false" update="false" class="com.argus.issueTracker.domain.vo.Project" outer-join="true" column="parent_id" cascade="none" />
<bag name="childProjects" order-by="project_id asc" outer-join="true" cascade="delete" inverse="true" >
<key column="parent_id"/>
<one-to-many class="com.argus.issueTracker.domain.vo.Project"/>
</bag>

</class>


Here's the problem.

In the above mapping file, I have 2 one-to-many collections that I am mapping. 1 is the child projects of this project, and another is the threads that this project contains (this is for a issue tracking app).

When I execute the following query
Code:
Criteria criteria = session.createCriteria(Project.class);
criteria.addOrder(Order.desc("creationDate"));
List projects = criteria.list();


DB entries look like
Code:
Projects Table
project_id           project_name               parent_id
1                        Base Project                  null
2                        Test Project                   null
3                        Base Sub 1                    1
4                        Base Sub 2                    1
5                        Test Sub 1                     2
6                        Test Sub 2                     2
7                        Test Sub 3                     2
8                        Base Sub 2                    1


Threads Table
thread_id            subject                    project_id
1                         Test                        1
2                         Test1                      1
3                         Test                        2
4                         Test1                      2




So what I expected to get back (beings I didn't put any where clause) was 8 entries.
Entries with ID 1 and 2 should each have a collection with 3 childProjects in it.
Each should also have a collection with 2 threads in it.

Instead what I get back is 10 entries. Projects 3-6 return as a single line, but projects 1 and 2 are duplicated becuase they each have 2 threads. It isn't duplicating the Projects based off fo the sub project size (becuase if it was it would have generated more than 10 results.

I am not posting the query becuase it would just fill the post up. But basically when it is building the mapped collection of childProjects it does so by issuing separate SQL statements (which help prevent duplication of the parent). For the threads, it tries to get them back in the same query as the projects, which results in duplicated rows.


Why is Hibernate giving me back duplicate entries for the "Projects" when there are multiple children?
What do I need to do to fix it?
Where can I find better documentation on this?

I have spent 2 days reading through the forum and the documentation, and nothing I have found addresses this. Also, the forum seriously needs a better search capability. A query either returns 2000+ rows or none........ But that's just my frustration coming out.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 11:28 am 
Beginner
Beginner

Joined: Wed Nov 24, 2004 10:54 am
Posts: 48
Did you get this resolved? I have a similar problem.


Top
 Profile  
 
 Post subject: Figured it out
PostPosted: Wed Jan 19, 2005 11:31 am 
Newbie

Joined: Thu Dec 02, 2004 3:51 pm
Posts: 8
Yes I did get it figured out, but I haven't messed with it in a while so I am trying to relay the answer from memory.

I believe it was caused by me telling the objects to do the outer join in my config file. I thought that would force Hibernate to use a outer join command in the SQL, but it also made it so that it seemed to ignore the parent child association correctly. So if I remember correctly, once I turned outer-join to false, everything worked.

I will try to get in today and double check that answer, and if it was something different i will try to post the actual fix, but I think it was the outer-join.


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.