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();