-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: year() function in hibernate 2.1.8
PostPosted: Sat May 05, 2007 3:56 am 
Newbie

Joined: Sat May 05, 2007 3:11 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.