-->
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: Filtering an entity by multiple child restrictions
PostPosted: Mon Sep 13, 2010 9:07 am 
Newbie

Joined: Thu Sep 03, 2009 12:37 pm
Posts: 13
Hi,

If I have a company/employee relation, how can I fetch all company which have female employees with name "Miller" AND male employees with name "Smith"?

My first (almost successful) attempt was to use a subquery, but I would also get companies with male Millers.

HQL:
Code:
select c from Company as c
    left join c.employee as e
    where e in
        (select e from Employees as e
            where (e.gender=1 and e.name='Smith')
            or (e.gender=2 and e.name='Miller') )


If there was a way to use more than one "e", I could do something like e1, e2 and associate them with "and" instead, but if I try to do so, I get an error (it's not possible to select a property more than once).


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.