Tuesday 15 March 2011

hibernate - How to dynamically search between two dates in hql? -


I have two date search fields from which to get the records from the user table, whose start date in the search field The dates are entered between and between the middle and between and if the dates are empty, then I have to recover all the records from the user table.

I tried the following HQL query:

  from the user where: start_flag = 1 or between STARTDATE: from and: to   < P> Here is the start_flag type int which is set to 1 and if is empty.  
  query.setParameter ("to", startDt); Query.setParameter ("from", endDt); Query.setParameter ("start_flag", startFlag); L = query.list (); Here are the data types:  

startDt - java.util.Date

endDt- java.util.Date

SQL error: 932, SQLState:

42000

ORA-00932: Incompatible datatype: expected on Dec 2 found

Can you tell me how to write the HQL query to achieve the above functionality?

Filter it like this:

  string query = "user From where: start_flag = 1 "; If (startDt! = Null & expiry data! = Null) {query start = between "or: start and date: end_date"; } Typed password & lt; USER & gt; Hql = entityManager.createQuery (query); If (startDt! = Null & expiry data! = Null) {hql.setParameter ("start_date", startDt) .setParameter ("end_date", endDt); } List & lt; USER & gt; Results = hql.setParameter ("start_flag", startFlag) .list ();    

No comments:

Post a Comment