-->
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 join fetching and duplicated _child_ objects
PostPosted: Thu Apr 27, 2006 3:34 am 
Beginner
Beginner

Joined: Fri Apr 09, 2004 12:47 pm
Posts: 36
Hi,
when running this HQL query:

from Rule r
left join fetch r.type t
left join fetch t.featureAttributeList attribute
left join fetch attribute.enumerationValues
left join fetch r.objectConditions oc
left join fetch oc.geometryConditions
left join fetch oc.attributeChecks
where r.id = ?

I got a list of duplicated Rule objects, and this is expected, but I also got
duplicated items in the featureAttributeList collection, and this is new to me.

Have I spotted a bug? Every collection is a List mapped with the @OneToMany annotation with all/delete_orphan cascade style, and from the debugger it seems this results in a PersistentBag type of collection. Each collection is mapped from the parent to the childs, but not the other way around (so these are not bi-directional).

What should I do? I need to efficiently retrieve a Rule, but this behaviour makes it more or less impossible...
Oh, btw, the other collections (object conditions, geometry conditions, attribute checks) are empty at the moment.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 10:40 am 
Newbie

Joined: Wed Apr 26, 2006 3:08 pm
Posts: 3
Hey man..

I´ve experienced this too.. when u have a join with two or more one-to-many associations the results will be duplicated..

what I do is manually remove the duplicated itens from all the lists using generic function in my framework...

well. it hapens becouse the lists are mapped as bags.. i think if you map them as Set this should not happen anymore..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 12:42 pm 
Beginner
Beginner

Joined: Fri Apr 09, 2004 12:47 pm
Posts: 36
I know that I can solve the problem using Sets, but I'd really like to avoid changing the interfaces in my model classes.

What I wanted to know is, is this intended, or is it a bug?
The documentation say "Note that queries that make use of eager fetching of collections usually return duplicates of the root objects (but with their collections initialized). You can filter these duplicates simply through a Set."

My problem here is that I get duplicates also outside the root objects returned by the query. The documentation also says "Join fetching multiple collection roles also sometimes gives unexpected results for bag mappings, so be careful about how you formulate your queries in this case"

Someone cares to elaborate how should I formulate my queries to avoid the "unexpected"?


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.