-->
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: how to write a hql along with "`" for select state
PostPosted: Mon Feb 05, 2007 3:14 am 
Beginner
Beginner

Joined: Mon Feb 05, 2007 2:33 am
Posts: 32
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:[Un known]

[b]Mapping documents:
<class name="com.ams.dao.message.MsgSms" table="msgsms">
<id name="smsid" column="sms_id" type="java.math.BigDecimal">
<generator class="increment" />
</id>
<property name="from" column="from" type="java.lang.String" />
<property name="to" column="to" type="java.lang.String" />
<property name="flow" column="flow" type="java.lang.String" />
<property name="date" column="date" type="java.lang.String" />
<property name="massage" column="massage"
type="java.lang.String" />
<property name="massagetype" column="massage_type"
type="java.lang.String" />
<property name="readstatus" column="read_status"
type="java.lang.String" />
<many-to-one name="status" column="status_id"
class="com.ams.dao.general.GnlKeyword" property-ref="keywordkey">
</many-to-one>
<many-to-one name="flag" column="flag_id"
class="com.ams.dao.general.GnlKeyword" property-ref="keywordkey">
</many-to-one>
</class>

[b]Code between sessionFactory.openSession() and session.close():


Full stack trace of any exception that occurs:

lSalskfdjaslkdfjs from com.ams.dao.message.MsgSms where `from` like '%siya%' or
`to` like '%siya%' or massage like '%siya%'
org.hibernate.QueryException: unexpected char: '`' [ from com.ams.dao.message.Ms
gSms where `from` like '%siya%' or `to` like '%siya%' or massage like '%siya%']
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorIm
pl.java:192)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl
.java:109)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCa
che.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessio
nImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImp
l.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
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.hibernate.context.ThreadLocalSessionContext$TransactionProtection
Wrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.createQuery(Unknown Source)
at com.ams.dao.AMSDao.find(AMSDao.java:77)
at com.ams.dao.message.MsgSms.searchSms(MsgSms.java:153)
at com.ams.business.message.MsgSmsActionBo.searchSms(MsgSmsActionBo.java
:75)
at com.ams.action.message.MsgSmsAction.searchSms(MsgSmsAction.java:89)
at com.ams.action.message.MsgSmsAction.handleAction(MsgSmsAction.java:48
)
at com.ams.action.AMSAction.execute(AMSAction.java:60)
at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
tProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:148
2)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:16
0)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:793)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:702)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:571)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:644)
at java.lang.Thread.run(Thread.java:595)
Caused by: line 1:40: unexpected char: '`'
at org.hibernate.hql.antlr.HqlBaseLexer.nextToken(HqlBaseLexer.java:278)

at antlr.TokenBuffer.fill(TokenBuffer.java:69)
at antlr.TokenBuffer.LA(TokenBuffer.java:80)
at antlr.LLkParser.LA(LLkParser.java:52)
at org.hibernate.hql.ast.HqlParser.weakKeywords(HqlParser.java:281)
at org.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser
.java:2366)
at org.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBasePar
ser.java:2331)
at org.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBasePars
er.java:2296)
at org.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:2
082)
at org.hibernate.hql.antlr.HqlBaseParser.logicalExpression(HqlBaseParser
.java:1858)
at org.hibernate.hql.antlr.HqlBaseParser.whereClause(HqlBaseParser.java:
454)
at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:70
8)
at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.j
ava:296)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:15
9)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.j
ava:238)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorIm
pl.java:155)
... 49 more
ERROR [http-8080-Processor25] (AMSDao.java:83) - Argh ! Error occurred while fin
ding object from com.ams.dao.message.MsgSms where `from` like '%siya%' or `to`
like '%siya%' or massage like '%siya%': org.hibernate.QueryException: unexpecte
d char: '`' [ from com.ams.dao.message.MsgSms where `from` like '%siya%' or `to`
like '%siya%' or massage like '%siya%']
WARN [http-8080-Processor25] (RequestProcessor.java:538) - Unhandled Exception
thrown: class java.lang.NullPointerException


Name and version of the database you are using:[mysql 5.0]

[b]The generated SQL (show_sql=true):


Debug level Hibernate log excerpt:



In this session i have doubt of how to use the ` this quote in the hibernate.

where as in my project the db field name is set as from which is a keyword of sql

so we need to specify the query as

select * from msgsms where `from` like '%a%';

while i am executing this query the hibernate throws me an unexpected token error . how to retify it . please help me


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 05, 2007 6:37 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi bharani

use alias for

try


select ms from msgsms ms where ms.from like '%a%';

_________________
Dharmendra Pandey


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.