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.  [ 7 posts ] 
Author Message
 Post subject: hql IN clause
PostPosted: Fri Oct 24, 2003 7:57 am 
Newbie

Joined: Wed Oct 15, 2003 3:20 pm
Posts: 9
Location: Montreal
Hi

Chapter 9.8. Expressions says that there is a IN clause but how can we use it.
I have something like this and I'd like to use the in clause for a NUMBER field.

String queryString = "select acc from cgix.trust.domain.PtbnAccount as acc where acc.accountId IN =: accountdId";
Query query = session.createQuery (queryString);
query.setParameter("accountId", accountFilter); ???????

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 8:01 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use it like this:

where a.ID in (1, 2, 3)

to match all IDs with either a value of "1", "2" or "3".

Just remove the "IN" in your query.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: object lists
PostPosted: Fri Oct 24, 2003 3:40 pm 
Newbie

Joined: Tue Oct 21, 2003 3:41 am
Posts: 5
Location: Belgium
Hello,

You may also use the setParameterList() to specify objects for the in-clause

Code:
...from net.sourceforge.myproject.Order order where order.owner in (:theListOfOnwers)...
query.setParameterList(allowedOwners)


Kind regards,

Dimitry D'hondt

_________________
Dimitry D'hondt
IT Architect - Real Software n.v.
http://www.realsoftware.be

Author of 'Smile' an open-source JaveServer Faces implementation. (http://smile.sourceforge.net)


Top
 Profile  
 
 Post subject: Re: hql IN clause
PostPosted: Tue Dec 22, 2009 12:30 pm 
Newbie

Joined: Tue Dec 22, 2009 12:15 pm
Posts: 1
SQL in clause has a size limit which depends on the database.

What about the HQL in clause ?


Top
 Profile  
 
 Post subject: Re: hql IN clause
PostPosted: Tue Dec 22, 2009 12:52 pm 
Beginner
Beginner

Joined: Tue Nov 03, 2009 9:38 am
Posts: 24
We do it like this (building upon your example):

String queryString = "select acc from cgix.trust.domain.PtbnAccount as acc where acc.accountId IN (:accountdIds)";
Query query = session.createQuery (queryString);
query.setParameter("accountIds", accountFilter); //assuming accountFilter is a List object

Keep in mind that you should not pass empty lists since that would result in the following SQL (which is likely not to work):
" ... WHERE xyz IN () ..." (note the empty in-clause).


Top
 Profile  
 
 Post subject: Re: hql IN clause
PostPosted: Sat Apr 10, 2010 8:11 am 
Newbie

Joined: Sat Apr 10, 2010 8:07 am
Posts: 1
yeah i was also facing problem to read that now i am cleared in this regard

_________________
70-640 dumps Knowledge CISSP dumps Help braindumps Study 220-701 dumps


Top
 Profile  
 
 Post subject: Re: hql IN clause
PostPosted: Sat Apr 17, 2010 4:09 pm 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
About the preparedstatements params in the DB. You're right it's DB dependent, normally that limit it's near or beyond of 255 for a single prepared stmts. pdao19 i think that you don't need to worry about this, if you see that this it's giving you somekind of error then you could execute the same query by spliting the parameters that you're using in the "in" clause to avoid it.

Regards,


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