[昨日调试]Named query not known: Employee.findByName

版权声明:本文为博主原创文章,但是你也可以随意转载。 https://blog.csdn.net/smartcore/article/details/79975645

又是拿到一个三方的前置应用,在使用前一篇《[昨日调试]在本地运行三方公司开发的maven项目》的方案做好依赖包的非仓库本地化后,idea内使用mvn clean package -DskipTests,开始生成war包,一切顺利。

然后开始进系统(localhost:port/login.on),输入完用户名、密码,点击登录,然后系统跳转到含有本文标题的错误页面:

Named query not known: Employee.findByName

 

因为对hibernate使用少,再加上mvn生成表面上是成功的(war包里的内容初看该有的都有了),所以首先感觉是hiberate的配置哪儿有问题?(非常疑惑,觉得应用里面应该没有少的或者错的东西啊),就先搜搜此问题到底是因为什么原因,大概有以下:

1、有说是<query>在<class>里的,请见:https://blog.csdn.net/daryl715/article/details/1518900

2、Entity注解的引用类错误,请见:https://stackoverflow.com/questions/10261651/named-query-not-known-for-named-hibernate-query

 

有需要的同学可以参考以上,但我的问题并不是因为以上的问题。

最终发现,是src/main/java/com/xxx/bizpro/entity下面的xml文件集没有包含在生成的war包里,真是意外,pom.xml完成没有关于<resource>的配置啊,你们是怎么打包到war里的[捂脸]。

随即使用通用方案在pom.xml里新增下面的片段:

<build>
<!-- 其他配置 -->
<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>com/xxx/bizpro/entity/**/*.xml</include>
        </includes>
    <resource>
</resources>
</build>



结束。

 

nested exception is org.hibernate.MappingException: Named query not known:

07-10

Exception in thread "main" org.springframework.orm.hibernate3.HibernateSystemException: Named query not known: select count(*) from (select m.cpuId cpuId, m.meterId meterId, cm.reading reading,cm.datetime datetime, o.Name operatorName,b.name buildingName,d.name departmentName, h.hNum hubId,h.Name hubName from Meter m, relationUserMeter rum, operators o, department d, relationBuildingMeter rbm, buildings b, Hubs h,(select r.cpuId,r.reading,r.dt datetime from readings r, (select cpuId, max(dt) datetime from readings group by cpuId) as temptable where r.cpuId=temptable.cpuId and r.dt=temptable.datetime) as cm where cm.cpuId=m.cpuId and m.cpuId=rum.cpuId and rum.operatorId=o.operatorId and o.departmentId=d.id and m.cpuId=rbm.cpuId and rbm.buildingId=b.id and cm.cpuId=rum.cpuId and cm.cpuId=rbm.cpuId and m.hub=h.hNum and h.hNum=?) a; nested exception is org.hibernate.MappingException: Named query not known: select count(*) from (select m.cpuId cpuId, m.meterId meterId, cm.reading reading,cm.datetime datetime, o.Name operatorName,b.name buildingName,d.name departmentName, h.hNum hubId,h.Name hubName from Meter m, relationUserMeter rum, operators o, department d, relationBuildingMeter rbm, buildings b, Hubs h,(select r.cpuId,r.reading,r.dt datetime from readings r, (select cpuId, max(dt) datetime from readings group by cpuId) as temptable where r.cpuId=temptable.cpuId and r.dt=temptable.datetime) as cm where cm.cpuId=m.cpuId and m.cpuId=rum.cpuId and rum.operatorId=o.operatorId and o.departmentId=d.id and m.cpuId=rbm.cpuId and rbm.buildingId=b.id and cm.cpuId=rum.cpuId and cm.cpuId=rbm.cpuId and m.hub=h.hNum and h.hNum=?) arnCaused by: org.hibernate.MappingException: Named query not known: select count(*) from (select m.cpuId cpuId, m.meterId meterId, cm.reading reading,cm.datetime datetime, o.Name operatorName,b.name buildingName,d.name departmentName, h.hNum hubId,h.Name hubName from Meter m, relationUserMeter rum, operators o, department d, relationBuildingMeter rbm, buildings b, Hubs h,(select r.cpuId,r.reading,r.dt datetime from readings r, (select cpuId, max(dt) datetime from readings group by cpuId) as temptable where r.cpuId=temptable.cpuId and r.dt=temptable.datetime) as cm where cm.cpuId=m.cpuId and m.cpuId=rum.cpuId and rum.operatorId=o.operatorId and o.departmentId=d.id and m.cpuId=rbm.cpuId and rbm.buildingId=b.id and cm.cpuId=rum.cpuId and cm.cpuId=rbm.cpuId and m.hub=h.hNum and h.hNum=?) arn at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:70)rn at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1260)rn at org.springframework.orm.hibernate3.HibernateTemplate$32.doInHibernate(HibernateTemplate.java:899)rn at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:362)rn at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedQuery(HibernateTemplate.java:897)rn at com.ehongyue.commons.dao.impl.QuerySupportImpl.findPageByNamedQuery(QuerySupportImpl.java:36)rn at com.ehongyue.commons.dao.impl.QuerySupportImpl.findPageByNamedQuery(QuerySupportImpl.java:28)rn at com.qj.example.service.impl.HubManageServiceimpl.getList(HubManageServiceimpl.java:90)rn at com.qj.example.service.impl.HubManageServiceimpl$$FastClassByCGLIB$$99f7e2a4.invoke()rn at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)rn at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:674)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)rn at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:615)rn at com.qj.example.service.impl.HubManageServiceimpl$$EnhancerByCGLIB$$8bd65cb3.getList()rn at com.qj.test.test.main(test.java:22)rn

ERROR org.hibernate.impl.SessionFactoryImpl - Error in named query: searchFilm

12-08

这是报错代码rn2687 [http-8080-2] ERROR org.hibernate.impl.SessionFactoryImpl - Error in named query: searchFilmrnorg.hibernate.MappingException: Unknown entity: cn.jbit.cniema.entity.FilmInforn at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:628)rn at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.getSQLLoadable(SQLQueryReturnProcessor.java:335)rn at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processRootReturn(SQLQueryReturnProcessor.java:376)rn at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.processReturn(SQLQueryReturnProcessor.java:355)rn at org.hibernate.loader.custom.sql.SQLQueryReturnProcessor.process(SQLQueryReturnProcessor.java:171)rn at org.hibernate.loader.custom.sql.SQLCustomQuery.(SQLCustomQuery.java:87)rn at org.hibernate.engine.query.NativeSQLQueryPlan.(NativeSQLQueryPlan.java:67)rn at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:136)rn at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:524)rn at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:394)rn at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)rn at cn.jbit.cinema.util.HibernateUtil.(HibernateUtil.java:13)rn at cn.jbit.cinema.dao.impl.BaseHibernateDAO.getSession(BaseHibernateDAO.java:16)rn at cn.jbit.cinema.dao.impl.FilmInfoDAO.search(FilmInfoDAO.java:30)rn at cn.jbit.cinema.biz.FilmInfoBiz.search(FilmInfoBiz.java:18)rn at cn.jbit.cinema.servlet.FilmSearchServlet.doPost(FilmSearchServlet.java:110)rn at cn.jbit.cinema.servlet.FilmSearchServlet.doGet(FilmSearchServlet.java:46)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)rn at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)rn at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)rn at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)rn at java.lang.Thread.run(Thread.java:722)rn建立SessionFactory错误org.hibernate.HibernateException: Errors in named queries: searchFilmrn十二月 08, 2011 6:56:26 下午 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet FilmSearchServlet threw exceptionrnjava.lang.NoClassDefFoundError: Could not initialize class cn.jbit.cinema.util.HibernateUtilrn at cn.jbit.cinema.dao.impl.BaseHibernateDAO.closeSession(BaseHibernateDAO.java:12)rn at cn.jbit.cinema.dao.impl.FilmInfoDAO.search(FilmInfoDAO.java:49)rn at cn.jbit.cinema.biz.FilmInfoBiz.search(FilmInfoBiz.java:18)rn at cn.jbit.cinema.servlet.FilmSearchServlet.doPost(FilmSearchServlet.java:110)rn at cn.jbit.cinema.servlet.FilmSearchServlet.doGet(FilmSearchServlet.java:46)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)rn at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)rn at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)rn at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)rn at java.lang.Thread.run(Thread.java:722)rnrn其中searchFilm是我在相关FIlmInfo.hbm.xml文件中的本地SQL语句的名字如下rn rn rn select f.*,t.* from filminfo f, filmtype t rn where rn (f.typeid=t.typeid) and rn (f.filmname like :name) and rn (f.actor like :actor) and rn (f.director like :director) and rn (f.typeid like :typeid) and rn (f.ticketprice between :smallprice and :bigprice) rn rn rn rn rn 求帮助看一下报错的原因?

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭