-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL retrieve based on a date column
PostPosted: Wed Oct 08, 2008 4:07 am 
Newbie

Joined: Mon Jun 20, 2005 11:14 pm
Posts: 13
version: Hibernate-Version: 3.2.4.sp1

how to write a HQL statement which retrieve record based on date part of a column only, not include time portion?
I see some forums say using trunc() function, but I got sql grammar exception.

15:17:43,102 [Timer-1] ERROR JDBCExceptionReporter - 'trunc' is not a recognized
function name.
15:17:43,542 [Timer-1] ERROR InitServlet - Exception in BackendTimerTask
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execu
te query; nested exception is org.hibernate.exception.SQLGrammarException: could
not execute query
Caused by:
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.j
ava:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelp
er.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2223)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.ja
va:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java
:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.armitage.royalGarden.store.InventoryBeanDaoImpl$1.doInHibernate(I
nventoryBeanDaoImpl.java:65)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(Hibernat
eTemplate.java:372)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(Hibernat
eTemplate.java:338)
at com.armitage.royalGarden.store.InventoryBeanDaoImpl.getRoomInventoryM
apByDate(InventoryBeanDaoImpl.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti
on(AopUtils.java:304)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJo
inpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.in
voke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynami
cAopProxy.java:204)
at $Proxy15.getRoomInventoryMapByDate(Unknown Source)
at com.armitage.royalGarden.extension.InitServlet$BackendTimerTask.run(I
nitServlet.java:86)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
--------------------------------------------------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2008 6:07 am 
Newbie

Joined: Fri Oct 03, 2008 2:30 am
Posts: 16
Location: Neuchâtel, Switzerland
First, you should post your HQL query instead of the exception!
As you may have read, trunc is not a HQL function.

But these functions are: DAY(d), MONTH(d), YEAR(d): Extracts the date from a temporal argument.

I don't know if it's possible to do this in one step with CAST(t as Type).


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

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.