-->
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: createCriteria and filtered collections
PostPosted: Sun May 13, 2012 5:06 pm 
Beginner
Beginner

Joined: Sun Jan 16, 2005 5:45 pm
Posts: 24
Location: Atlanta
I would like to create query that returns a list of all entities (i.e. classes) but filters entities in a associated collection (i.e students). Is that possible using a createCriteria query? Consider two tables ClassInfo and StudentInfo. I want to query ClassInfo to get all classes but only include StudentInfo entities in the students collection where the student made an "A" in the class.

if I write something like

List<ClassInfo> classes = session.createCriteria(ClassInfo.class).createCriteria("students").add(Restrictions.eq("grade","A").list();

This restricts the class entities to classes where where at least one student made an "A". I would like the list to contain ALL classes and filter the student enties. In some cases the students list will be empty... This is ok and expected.

Is this possible with createCriteria? How?

Thanks in advance?


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.