-->
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.  [ 6 posts ] 
Author Message
 Post subject: Equivalent of Restrictions.in for HQL
PostPosted: Tue Apr 12, 2005 7:33 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
In Hibernate 3, you can use Restrictions.in to filter a criteria based on the values of a collection.

Is there an equvialent in HQL so rather than hard coding the values as below

Code:
from DomesticCat cat where cat.name not in ( 'Foo', 'Bar', 'Baz'


I can do something like this instead ?

Code:
from DomesticCat cat where cat.name not in ( :catNameList )

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 8:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
paul, did you ever consider trying to look in the docs for this ?

Its right in there with the exact same syntax.

searching for " in (" on http://www.hibernate.org/hib_docs/v3/re ... ml_single/ will reveal it for you.

:)

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 8:30 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
max wrote:
paul, did you ever consider trying to look in the docs for this ?


Yes, I looked through the entire section on the where clause (14.7) and expressions(14.8) and the examples there where similar but referencing collections on mapped objects rather than collections passed in as parameters in the hql

I also did an entire search on the single html documention for in(, but not in ( as you suggested.

Thanks for pointing out the documentation location (its actually in the section on bind parameters for those who need to find it 10.4.1.4 as of the time of writing).

A slight amendment to the doucmentation might be useful, as I did look fairly hard for it.

Thanks though !

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 8:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
how would an ammendment to the docs help here ? Its right there with how to bind parameters ?

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 10:25 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
max wrote:
how would an amendment to the docs help here ? Its right there with how to bind parameters ?

/max


because its just mentioned in passing as an example of a named parameter in the bind parameters section as opposed to being explicitly mentioned in the section on the where clause.

If it had been here

Code:
in and between may be used as follows:

from DomesticCat cat where cat.name between 'A' and 'B'

from DomesticCat cat where cat.name in ( 'Foo', 'Bar', 'Baz' )

from DomesticCat cat where cat.name in ( :catNameCollection )


I would have found it straight away.

Don't worry about it.

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 10:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so for every time we show a query with a constant we should show how you do it with bind parameters - that gets very redundant ,)

but we could probably improve it with a link to the bind parameter section. A contribution for this is welcome - but no promises ,)


/max

_________________
Max
Don't forget to rate


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