org.hibernate.hql.internal.ast.ErrorCounter reportError

时间:2015-09-02 12:13:48

标签: hibernate

TX = session.beginTransaction();
         查询q = session.createQuery(“将产品更新为p set p.quantity =:n,其中p.id =:i”);
        q.setParameter( “N”,1000);
        q.setParameter( “I”,11);

    int status=q.executeUpdate();  
    System.out.println(status);

当我在hibernate中执行上面的代码

时,我得到了以下异常

2015年9月2日下午5:23:46 org.hibernate.hql.internal.ast.ErrorCounter reportError 错误:第1:8行:意外令牌:在 2015年9月2日下午5:23:46 org.hibernate.hql.internal.ast.ErrorCounter reportError 错误:第1:8行:意外令牌:在 第1:8行:意外的令牌:in     在org.hibernate.hql.internal.antlr.HqlBaseParser.updateStatement(HqlBaseParser.java:239)     在org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:169)     在org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:295)     在org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203)     在org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)     在org.hibernate.engine.query.spi.HQLQueryPlan。(HQLQueryPlan.java:131)     在org.hibernate.engine.query.spi.HQLQueryPlan。(HQLQueryPlan.java:93)     在org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)     at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)     在org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)     在org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1836)     at in.edu.pondiuni.service.ProductIssuedService.deleteFromProduct(ProductIssuedService.java:41)     at in.edu.pondiuni.controller.ProductIssuedServlet.processRequest(ProductIssuedServlet.java:78)     at in.edu.pondiuni.controller.ProductIssuedServlet.doGet(ProductIssuedServlet.java:90)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:620)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:727)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)     在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)     在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)     在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)     在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)     在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)     在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)     在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)     at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:607)     at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:315)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)     在java.lang.Thread.run(Thread.java:744)

1 个答案:

答案 0 :(得分:0)

这是一个开放的错误,如果实体位于以" in"开头的包中,则HQL查询失败。或" by"。供您参考view this link

您可以通过在hbm.xml中添加entity-name属性来解决此问题。

<class name="in.package.Entity" entity-name="Entity" table="MY_TABLE">