-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to pass parameter list to the IN operator?
PostPosted: Tue Oct 28, 2003 8:39 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
There is setParameterList method in the Query interface which allows creating constructs like:
WHERE id IN (?)

How is it possible to pass such an list to the SQL expression?

I mean criteria.add(Expression.sql ( " ... WHERE id IN (?) ..." ) )


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 9:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is not supported. Whats wrong with Expression.in() ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 9:52 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Only one problem with Expression.in - I have no idea how to use it in my context.

I have Employees & Skills ... (yep, Gavin, you have already seen this -
http://forum.hibernate.org/viewtopic.php?t=925086 ) And I need to find all employees who has ALL of requested skills. This query works fine:

Criteria query = session.createCriteria(Employee.class)
.add(Expression.sql(
"( " +
" SELECT COUNT(es.skill_id) " +
" FROM EMPLOYEE_SKILL es " +
" WHERE es.employee_id = {alias}.employee_id AND" +
" es.skill_id in (65, 66, 67) " +
") = 3"
));

When I want to remove static skill list (65, 66, 67) and pass it as parameter - I'm in trouble.

I'm trying to use Criteria because of Example query API - I need search by name in addition to search by skills.

If you could propose a better way (or a more "Hibernate way")...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 28, 2003 5:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I think that these kinds of queries are much better expressed in HQL, which has full support for subqueries.


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