Hibernate version: 2.1.8
Mapping documents:
<hibernate-mapping>
<class name="com.corebrick.qols.repository.CourseAttendedLog" table="O_COURSE_ATTENDED_LOG">
<cache usage="read-write" />
<id name="recId" column="REC_ID" type="long">
<generator class="increment"/>
</id>
<property name="courseAttendedDate" column="COURSE_ATTENDED_DATE" type="timestamp" />
<property name="publishedOn" column="PUBLSHED_ON" type="timestamp" />
<property name="author" column="AUTHOR" type="string" />
<property name="userId" column="USER_ID" type="string" />
<property name="repositoryEntryFK" column="REPOSITORYENTRY_FK" type="long" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
String sql ="select cl.repositoryEntryFK,cl.publishedOn,cl.author,year(cl.courseAttendedDate) from com.corebrick.qols.repository.CourseAttendedLog as cl
where cl.courseAttendedDate >= :fromDate and cl.courseAttendedDate <= :toDate ";
DBQuery dbquery = DB.getInstance().createQuery(sql).setDate("fromDate",fromDate).setDate("toDate",toDate);
List yearlyData=dbquery.list();
Full stack trace of any exception that occurs:
cause::net.sf.hibernate.QueryException: undefined alias: year [select cl.repositoryEntryFK,cl.publishedOn,cl.author,year(cl.courseAttendedDate) from com.corebrick.qols.repository.CourseAttendedLog as cl
where cl.courseAttendedDate >= :fromDate and cl.courseAttendedDate <= :toDate ] -> at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:103) at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29) at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:170) at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87) at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114) at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143) at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30) at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149) at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138) at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295) at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1572)
Name and version of the database you are using:
MySQL 5.x
The generated SQL (show_sql=true):
No SQL is generated.Throws Exception before generating exception
Debug level Hibernate log excerpt:
Description: I am getting the above exception with hibernate 2.1.8. When I use the same code with HSQLDB works fine without any changes. When I try to use the same code with MySQL , the I get the exception/error message as mentioned above. I have also come across another forum which says there is the same issue with Oracle DB also. If year() date function is not supported in this version, how is that HSQLDB doesnt have any problems with it? Is there any workaround for this??
Thanks
Vinod
|