• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Dynamic bind variables

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi There,

I am using a named query and in one of the where clause condition I need one or more values in the IN Clause like as follows:

select t.x, t.y from Table t
where t.date between ? and ?
and t.types in (one or more values based on user action).

Is there a way of accomplishing the above without using a Criteria API to build dynamic HQL.

Any help would be greatly appreciated.

Thanks and Regards,
Agasthya
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. There is.
Try giving us some sample code you have written, we might be able to help you further.
 
Agasthya Iyer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi There,

I changed my namedQuery to use named parameters like

select t.x, t.y from table t
where t.description = escription
and t.types in (:typesList)

Query query = session.getNamedQuery(queryName);
String[] paramNames = query.getNamedParameters();
if(args.length == paramNames.length) {
for(int i = 0; i < paramNames.length; i++) {
if(paramNames[i].endsWith("List")) {
query.setParameterList(paramNames[i], (List)args[i]);
}else {
query.setParameter(paramNames[i], args[i]);
}
}

where args is an Object[] of the values that I need to bind to the namedParameters in the order in which it is laid out in the Named Query
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic