Hibernate中in expected错误的原因之一

来源:互联网 发布:找保镖什么软件 编辑:程序博客网 时间:2024/04/30 13:01

今天在执行语句查询时发现怎么都执行不了,换数据库别的表可以执行,以为是数据库表生成时哪里出了问题,一遍又一遍的对映射文件,数据库表,就是没有想出到底哪儿错了,还删了表重新生成表和索引,都没有办法。在网上看了一下资料突然明白,在Spring中没有配置BO。真晕!

出现错误是:

执行查询的时候出了如下错误:
net.sf.hibernate.QueryException: in expected: t [from TbApplyNew t]
     at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
     at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
     at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:139)
     at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
     at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:146)
     at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:133)
     at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:352)
     at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:330)
     at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1368)
     at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1332)
     at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:76)
     at com.ninetowns.ods.srvvervst.ServiceVersionVisitManager.getVisitSuRecords(ServiceVersionVisitManager.java:79)
     at com.ninetowns.ods.srvvervst.ServiceVersionVisitManagerTest.testGetVisitSuRecords(ServiceVersionVisitManagerTest.java:37)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:324)
     at junit.framework.TestCase.runTest(TestCase.java:154)
     at junit.framework.TestCase.runBare(TestCase.java:127)
     at junit.framework.TestResult$1.protect(TestResult.java:106)
     at junit.framework.TestResult.runProtected(TestResult.java:124)
     at junit.framework.TestResult.run(TestResult.java:109)
     at junit.framework.TestCase.run(TestCase.java:118)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
 
原因是使用了三层框架:struts+hibernate+spring,在spring配置文件中没有注入hibernate类对应的xml映射文件.
<bean id="hibernateMapping.strongbpm.bpmnew" class="com.strongit.finance.common.util.ListHelper">
     <property name="mappings">
      <list>
     <!-- 业务表配置文件在此注入 -->
    <value>com/strongit/strongbpm/bo/TbApplyNew.hbm.xml</value>
    <value>com/strongit/strongbpm/bo/TbApporeNew.hbm.xml</value>
   </list>
     </property>
    </bean>
如果没有使用spring,只是使用了hibernate那么则Hibernate类对应的xml映射文件中的表名和包、类没有修改过来,然后在hibernate.cfg.xml文件中添加对应的记录。