Solved

HQL query needed

Posted on 2011-09-22
2
390 Views
Last Modified: 2012-06-21
Hi - I need a HQL query for the following

select * from table where name in('name1','name2') and created_date >= to_date('01/01/2011','MM/dd/yyyy') and updated_date <= to_date('09/21/2011','MM/dd/yyyy')

Thanks
0
Comment
Question by:abuyusuf35
2 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36584547


I think is should be like that:

Query query = session.createQuery("from Table as table where table.name in ('name1','name2') and table.created_date >= :startDate and table.updated_date <= :endDate");
query.setDate("startDate", Date.valueOf("2011-01-01");
query.setDate("endDate", Date.valueOf("2011-09-21");

Open in new window


0
 
LVL 21

Accepted Solution

by:
Amitkumar Panchal earned 500 total points
ID: 36708427
Try the following


List variableList = new ArrayList();
variableList.add("name1");
variableList.add("name2");
Query query = session.createQuery("from Table as table where table.name in (:nameList) and table.created_date >= :startDate and table.updated_date <= :endDate");
query.setDate("nameList", variableList);
query.setDate("startDate", Date.valueOf("2011-01-01"));
query.setDate("endDate", Date.valueOf("2011-09-21")); 

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
print map entry 34 71
Why my table column Id is not passed to java object? 4 44
Error in @AspectJ Based AOP with Spring 2 18
What browser will run Java? 7 41
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question