Guys I am new to hibernate. I am working on simple example.
I want to fetch the data from the table based on the date coloumn.
date format of the coloumn : 9/18/2007 12:37:14 AM
the Sql query look likes this :
select * from epat_login_info_tmp where to_date(login_time,'mm-dd-yy') = to_date(sysdate,'mm-dd-yy')
I want the HQL query which performs the same task as the above SQL query.
the HQL query i tried was:
from UserInfoVo uv where to_date(uv.loginDate,'dd-mm-yy') = to_date(sysdate,'dd-mm-yy')
but i get the below specified exception.can you tell me where is the mistake
I want to format the date coloumn in 'mm-dd-yy' format using HQL and reterive the data by sepecifing the date range.
pls help me on this.
Hibernate version:
hibernate0 - 3.0
Mapping documents:
<hibernate-mapping>
<class name="com.igate.vo.UserInfoVo" table="EPAT_LOGIN_INFO_TMP">
<id name="seqId" column="SEQ_ID" type="int"></id>
<property name="racfID" column="RACF_ID" type="string"/>
<property name="fname" column="FNAME" type="string"/>
<property name="lname" column="LNAME" type="int"/>
<property name="loginDate" column="LOGIN_TIME" type="date"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
String toDate = formatter.format(date);
System.out.println("date"+toDate);
session= HibernateUtil.getSessionFactory().openSession();
Query q = session.createQuery("from UserInfoVo uv where to_date(uv.loginDate,'dd-mm-yy') = to_date(sysdate,'dd-mm-yy')");
List results = q.list();
Full stack trace of any exception that occurs:
java.lang.Exception: org.hibernate.exception.GenericJDBCException: could not execute query
Name and version of the database you are using:
oracle
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.ht[/b]