-->
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: Named Query Problem
PostPosted: Tue Jul 10, 2007 2:07 am 
Newbie

Joined: Tue Jul 10, 2007 1:32 am
Posts: 1
Hello I have the following query
String HQL =
SELECT IO.IO_ID AS IO_ID, IO.IO_TYPE_ID AS IO_TYPE_ID, IO_TYPE.IO_TYPE_NAME AS IO_TYPE_NAME,
IO.IO_NAME AS IO_NAME, IO.GIST AS GIST, GEO.LATITUDE AS LATITUDE, GEO.LONGITUDE AS LONGITUDE
from IO_DATA IO, IO_GEOMETRY GEO, IO_TYPE_TABLE IO_TYPE
where IO.IO_ID=GEO.IO_ID
and IO.IO_TYPE_ID=IO_TYPE.IO_TYPE_ID
and IO.STATUS_ID=1
and IO.IO_TYPE_ID in (5,4,3)
AND IO.BEGIN_DATE>=trunc(to_date(:startDate,'MM/DD/YYYY'))
AND IO.END_DATE<trunc(to_date(:endDate,'MM/DD/YYYY'))+1


I am passing the parameters startDate and endDate in HashMap and setting those as startDate='06/15/2007' and endDate='07/10/2007'. But when executing the following pice of code it is throwing the following exception

Session session = HibernateUtil.getSession();
Query query = session.createQuery(HQL);
ArrayList resultList = query.list();


10 Jul 10:45:58 ERROR com.ijet.data.handler.DataHandler: Exception
net.sf.hibernate.QueryException: in expected: IO [SELECT IO.IO_ID AS IO_ID, IO.IO_TYPE_ID AS IO_TYPE_ID, IO_TYPE.IO_TYPE
_NAME AS IO_TYPE_NAME, IO.IO_NAME AS IO_NAME, IO.GIST AS GIST, GEO.LATITUDE AS LATITUDE, GEO.LONGITUDE AS LONGITUDE from
IO_DATA IO, IO_GEOMETRY GEO, IO_TYPE_TABLE IO_TYPE where IO.IO_ID=GEO.IO_ID and IO.IO_TYPE_ID=IO_TYPE.IO_TYPE_ID and IO
.STATUS_ID=1 and IO.IO_TYPE_ID in (5,4,3) AND IO.BEGIN_DATE>=trunc(to_date(:startDate,'MM/DD/YYYY')) AND IO.END_DATE<tru
nc(to_date(:endDate,'MM/DD/YYYY'))+1]
at net.sf.hibernate.hql.FromParser.token(Ljava.lang.String;Lnet.sf.hibernate.hql.QueryTranslator;)V(FromParser.j
ava:102)
at net.sf.hibernate.hql.ClauseParser.token(Ljava.lang.String;Lnet.sf.hibernate.hql.QueryTranslator;)V(ClausePars
er.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(Ljava.lang.String;Lnet.sf.hibernate.hql.QueryTranslator;)V(Pre
processingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(Lnet.sf.hibernate.hql.Parser;Ljava.lang.String;Ljava.lang.String;Lnet
.sf.hibernate.hql.QueryTranslator;)V(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile()V(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(Lnet.sf.hibernate.engine.SessionFactoryImplementor;Ljava.util.Ma
p;Z)V(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(Ljava.lang.String;Z)[Lnet.sf.hibernate.hql.QueryTranslator;
(SessionFactoryImpl.java:293)
at net.sf.hibernate.impl.SessionImpl.getQueries(Ljava.lang.String;Z)[Lnet.sf.hibernate.hql.QueryTranslator;(Sess
ionImpl.java:1554)
at net.sf.hibernate.impl.SessionImpl.find(Ljava.lang.String;Lnet.sf.hibernate.engine.QueryParameters;)Ljava.util
.List;(SessionImpl.java:1525)


I am getting the above exception. If i am executing the query explicitly it is giving proper results. Plz help on this. Thanks in advance..........

Regards,
Hari Kumar


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 10, 2007 6:02 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

use

Session session = HibernateUtil.getSession();
Query query = session.createQuery(HQL);
query =query.setParameter("startDate","06/15/2007",Hibernate.STRING);
query =query.setParameter("endDate","07/10/2007",Hibernate.STRING);

ArrayList resultList = query.list();


Amila

(Don't forget to rate if helps)


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.