-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL question (I apologize in advance)
PostPosted: Mon Nov 24, 2003 5:18 pm 
Beginner
Beginner

Joined: Tue Sep 23, 2003 10:03 am
Posts: 26
Location: madison, wi
I've been looking over the HQL chapter and still can't figure this out.

I have an object, a User, who has a set of roles, called persistentRoles. I need to make a Hibernate query that returns all users who have no roles. The best I've come up with is this:

from users in class md.user.User where users.persistentRoles.elements is null

This works great and finds all the users with no roles. But if any user has more than one role, I get this error: "Could not execute query: Subquery returned more than 1 value."

Again, I apologize for my ignorance, but I just can't figure out the right way to do this. If I need to provide any more info, I would be happy to.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 5:29 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Try this:
Code:
from users in class md.user.User where not exists elements(user.persistentRoles)

Found in reference doc, chapter 9.8 Expressions

Another solution could be (haven't tried):
Code:
from users in class md.user.User where size(user.persistentRole) = 0


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 5:32 pm 
Beginner
Beginner

Joined: Tue Sep 23, 2003 10:03 am
Posts: 26
Location: madison, wi
Thank you, that worked perfectly. I guess in my skimming I missed this line:
Quote:
The SQL functions any, some, all, exists, in are supported when passed the element or index set of a collection (elements and indices functions) or the result of a subquery (see below).


Thanks again.


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