Solved

HQL query needed

Posted on 2011-09-22
2
387 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
Comment Utility


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 20

Accepted Solution

by:
Amitkumar Panchal earned 500 total points
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now