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
|