-->
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.  [ 2 posts ] 
Author Message
 Post subject: Counting child entities using criteria
PostPosted: Thu Jul 10, 2008 1:28 pm 
Newbie

Joined: Thu Jul 19, 2007 6:49 am
Posts: 13
Four hours, I've been trying to find the ICriteria equivalent for the following HQL query. And I've found no examples or leads anywere yet.

"select ex from Exams ex where ex.Examiners.size > 0"

In other words, I'd like to find all Exams that have at least one Examiner. I know that I probably need to use a DetachedQuery, but still, nothing works properly.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 3:08 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Try this:

Code:
DetachedCriteria dc = DetachedCriteria.For(typeof(Examiners),"exs")
     .Add(Expression.PropertyEq("ex.Id", "exs.Examid")
     .SetProjection(Projections.RowCount());

ICriteria crit = session.CreateCriteria(typeof(Exam),"ex")
     .Add(Subqueries.Exists(dc))
     .List<Exam>();

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.