-->
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: left out join fetch in find results in duplicated parents
PostPosted: Wed Jun 30, 2004 8:02 pm 
Beginner
Beginner

Joined: Wed Nov 19, 2003 6:46 pm
Posts: 41
Location: Auckland, New Zealand
Hi

Using Hibernate 2.1.4 on SQL Server

I have a simple parent child relationship between AuditEvent and AuditDetail classes.

The auditDetails set on my AuditEvent class is set to lazy="false".

I'm wanting to find all AuditEvent objects and their associated AuditDetail objects.

Now, I understand that for a find, Hibernate doesn't use outer join fetching. This means that I find all my AuditEvent objects in one SQL statement, and then there's another SQL statement for each of the found AuditEvent objects to load their AuditDetail objects.

The HQL for this is:

"from AuditEvent e"

So, I'm wanting to be more efficient and do only one SQL query.

I read in the documentation (section 11.3 Associations and joins) that I can use a "fetch" join to "allow associations or collections of values to be initialized along with their parent objects, using a single select."

So, I changed my HQL to:

"from AuditEvent e left outer join e.auditDetails"

But when I execute this, I get back duplicated AuditEvent objects - one for each AuditDetail object. So, if I had only one AuditEvent object, but 10 AuditDetail child objects, I'd get back 10 AuditEvent objects!

I have turned on debug logging for Hibernate and I can see that, in the case above with 1 AuditEvent and 10 AuditDetails that Hibernate is only hydrating 11 objects (1 AuditEvent, 10 AuditDetail), but it's returning me the same AuditEvent 10 times!

What am I missing here, or is this truly a bug?

Craig


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 8:06 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There is no bug, it is expected. Put your result in a Set: distinctResult = new HashSet(resultList);

http://www.hibernate.org/117.html#A11

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 8:11 pm 
Beginner
Beginner

Joined: Wed Nov 19, 2003 6:46 pm
Posts: 41
Location: Auckland, New Zealand
Wow... that was an incredibly quick reply!

Thanks, Christian!

Funnily I had read that FAQ yesterday, just didn't apply it to my situation today! :-)


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.