-->
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: Hibernate association and child collection not pre-filtered.
PostPosted: Fri Jan 02, 2009 10:20 am 
Newbie

Joined: Fri Jan 02, 2009 9:44 am
Posts: 2
Hello,

Could someone please explain why child collection in the parent is not pre-filtered by the criteria? This is described at: http://www.hibernate.org/hib_docs/refer ... tions.html
Why wouldn't a Cat instance not have only Kittens with name like "F%"?

The recommended solution is to use "setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)". However, each Kitten object is retrieved from the map using it's alias, not from within the Cat object.
Is there a solution where Cat-Kitten object graph could have the pre-filtered objects as per the criteria?

Thank you,
hibusr11.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2009 1:40 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
DISTINCT_ROOT_ENTITY ?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2009 9:38 am 
Newbie

Joined: Fri Jan 02, 2009 9:44 am
Posts: 2
Hello,

I tried using DISTINCT_ROOT_ENTITY.

However, there are still multiple child/Kitten objects that do not match the criteria restriction. Does DISTINCT_ROOT_ENTITY only filter out duplicate root/parent/Cat objects?

List cats = sess.createCriteria(Cat.class)
.createCriteria("kittens", "kt")
.add( Restrictions.eq("name", "F%") )
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.list();

Any thought on what I may be doing wrong?

Thank you for your response.
hibusr11


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.