-->
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: Detached criteria subquery
PostPosted: Fri Sep 17, 2010 3:41 pm 
Newbie

Joined: Mon Aug 02, 2010 10:56 am
Posts: 6
Hi, I need to do this SQL query with detachedCriteria:

Code:
SELECT g.id FROM games g
WHERE NOT EXISTS (SELECT 1 FROM users_games ug WHERE ug.user_id = 1 AND g.id = ug.game_id)


The idea is to get the ids from the games that aren't owned by the user.
I tried like 10 different approaches with detachedCriteria but I get the "Unknown entity: null" MappingException
The code should look like:
Code:
DetachedCriteria subquery = DetachedCriteria.forClass(UserGame.class, "ug")
   .add(Restrictions.eq("ug.user.id", 1))
   .add(Restrictions.eqProperty("ug.game.id","u.id"));
DetachedCriteria criteria = DetachedCriteria.forClass(Game.class, "g")
   .add(Subqueries.notExists(subquery));

Setting also the projections to return only the id of the games.

Any ideas?
I think Hibernate has some trouble joining the queries with no alias.
Adding alias works but the results are quite wrong.


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.