-->
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: How to pass objects to HQL query "in" operator.
PostPosted: Wed Jun 21, 2006 6:19 am 
Newbie

Joined: Mon May 08, 2006 1:07 am
Posts: 2
hi
i m new to Hibernate. i want to know whether i can pass List of objects to "in" operator in HQL or not. I think it works fine for strings.

Actually my HQL query is something like this:

"Select count(employees) from Employee employees where employees.category in ()"

i have a list named "categories" whose size changes dynamically and contains Objects of "Category" POZO.

Know i want to execute the above query, pasing this list to "in" operator.

And i Dont want to use "Expression.in", it consumes time.

Bye

Kamalpreet


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 7:50 am 
Regular
Regular

Joined: Mon May 08, 2006 6:00 am
Posts: 53
Location: India
Put following query in .hbm.xml file and run this as a named query

<query name="QueryName">
Select count(employees) from Employee employees where employees.category in ( :parameterList)"

<query>

in java class run it as

String parameterList = {} // This is array or category name

session.getNamedQuery("QueryName").setParameterList("parameterList",parameterList).executeUpdate();

Hope this helps

Sudhir

Pls rate if it helps


Top
 Profile  
 
 Post subject: Re: How to pass objects to HQL query "in" operator
PostPosted: Thu Jun 22, 2006 4:02 pm 
Beginner
Beginner

Joined: Fri Jun 02, 2006 1:14 am
Posts: 30
This is the pattern I use:

Code:
List titles = new LinkedList();
// ... add titles to the list ...
Query query = session.createQuery("from Bar where title in :titles");
query.setParameterList("titles", titles);
return query.list();


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.