-->
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: Criteria API - specifying result set
PostPosted: Thu May 19, 2005 10:18 pm 
Newbie

Joined: Thu May 19, 2005 2:00 am
Posts: 1
Can I use the Criteria API for a query that does not select results from the left-most entity in a join?

For example, I can run a query in HQL like so:

Code:
// List all clubs who have a player named John.
select club.name from Player as player
       inner join player.club as club
       where player.name = 'John'


Note that I am only selecting fields from the joined entity, `club', which is not the left-most entity. Is it possible to do this with the Criteria API?

(In my particular case, I cannot simply swap the entites around in the join, because it's not a bi-directional association.)


As far as I can tell, the Criteria API can only return entities from the left-most entity in the join. E.g.:

Code:
// List all players who have a club and are named John. I really want to list all clubs who have player named John.
List players = sess.createCriteria(Player.class)
    .add( Restrictions.equal("name", "John") )
    .createCriteria("club")
    .list();


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.