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.  [ 1 post ] 
Author Message
 Post subject: Distinct Entity Criteria Returns Same Entity N-times
PostPosted: Thu Mar 17, 2011 4:09 pm 
Beginner
Beginner

Joined: Fri Nov 13, 2009 4:05 pm
Posts: 30
I have an entity which has a relationship with two child collections, as shown here:

Parent
+-- Child (collection)
+-- GrandChild (collection)

What I want to have returned is the list of distinct parent entities where the grand child entity contains a property of a specific value. So long as only one of the grandchildren of a specific parent contain the value, I get a single hit; however as soon as multiple grandchildren contain this value, I get multiple parent entities returned.

Code:
Criteria parentCriteria = getSession().createCriteria(Parent.class);
parentCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

Criteria childCriteria = parentCriteria.createCriteria("children");
Criteria grandChildCriteria = childCriteria.creteCriteria("children");
grandChildCriteria.add(Restrictions.eq("propertyA", "valueA"));


Is there a way to work around this where I can still use the Criteria API to restrict my parent entities as desired but without having the parent returned multiple times when the grand child record has multiple matches?


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

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.