一个hibernate的jap查询无值报错问题!跪求大神回答!

问题描述

问题是这样我在做一个登录功能,用的是jap的EntityManager对象查询。查询语句:{Useruser=(User)em.createQuery("selectenfrom"+getEntityName(this.entityClass)+"asenwhereusName=:nameandusPsword=:pwd").setParameter("name",name).setParameter("pwd",pwd).getSingleResult();}问题出现了:当我输入正确用户名和密码时没有报错,但是我输入不正确用户名和密码时就会报出错误。就是想知道用EntityManager对象查询时,是不是当没有查询返回结果就会报错,该如何解决这个问题?错误信息:javax.persistence.NoResultException:Noentityfoundforqueryatorg.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:280)atcom.zuo.dao.impl.UserDaoImpl.userLogin(UserDaoImpl.java:40)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)atorg.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)at$Proxy21.userLogin(UnknownSource)atcom.zuo.service.impl.UserServiceImpl.userLogin(UserServiceImpl.java:31)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)atorg.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)atorg.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)atorg.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)at$Proxy24.userLogin(UnknownSource)atcom.zuo.action.UserAction.login(UserAction.java:34)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atcom.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:446)atcom.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:285)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)atorg.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)atcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)atorg.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)atcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238)atcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238)atcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atorg.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atorg.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atorg.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)atcom.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atorg.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atcom.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)atcom.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)atorg.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)atorg.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:544)atorg.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)atorg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)atorg.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)atorg.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)atjava.lang.Thread.run(Thread.java:619)

解决方案

解决方案二:
写错了不是jap时jpa
解决方案三:
在getSingleResult的源码里有这样一句:@throwsEntityNotFoundExceptionifthereisnoresult所以,你得处理异常.
解决方案四:
还是写个sql语句吧,简单多了...

时间: 2024-10-10 16:51:33

一个hibernate的jap查询无值报错问题!跪求大神回答!的相关文章

速度解决-接谷歌sdk报错!跪求大神!

问题描述 接谷歌sdk报错!跪求大神! 解决方案 我知道啊!只要连接外国的vpn就好了啊!我了解上了还是不行!就报这个错! 解决方案二: google在中国被限制了的

java-R字全部报错、跪求大神

问题描述 R字全部报错.跪求大神 eclipse 好好的java中R. 全报错 倒包后.大部分又引用不到了 如下图- 跪求大神 解决方案 http://www.itnose.net/news/142/6339412 解决方案二: 资源中有出错导致R.java没有生成 解决方案三: clean完还不行的话就是R包被强制删除了,可以考虑重新开工程了 解决方案四: 你这个主题颜色 很赞,请问是怎么弄得??

ssh整合-spring整合hibernate做测试时没有报错,当三个整合时启动就报错啦,求大神指点!!

问题描述 spring整合hibernate做测试时没有报错,当三个整合时启动就报错啦,求大神指点!! 报的错误org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'ecsUnsigned' on target class [class $Proxy17] failed; nested exception is org.springframework.tran

无线路由器低电-无线路由器串口下报错,在线求大神解决!!

问题描述 无线路由器串口下报错,在线求大神解决!! 一直报HSIC-USB in low power mode,求怎么退出低电模式,谢谢 解决方案 http://zhidao.baidu.com/link?url=vMCO-E0_utuzonHcMnZ-xoPinvjbujhVRmGBvNbLt8Pw8Jnz4BbOFjSrxv5I4oB-hEAwn3iajiIB6p-p3bUcEIn-Ev8KjeegkR7i85MVB6G

在tomcat上运行没有问题,在weblogic上运行就报下面的错,跪求大神帮忙

问题描述 在tomcat上运行没有问题,在weblogic上运行就报下面的错,跪求大神帮忙 java.sql.SQLException: Statement cancelled, probably by transaction timing out at weblogic.jdbc.wrapper.Statement.postInvocationHandlerNoWrap(Statement.java:128) at weblogic.jdbc.wrapper.PreparedStatement

程序运行就闪退,log日志报错如下,求大神支招

问题描述 程序运行就闪退,log日志报错如下,求大神支招 05-24 18:28:21.920 32733-32733/com.example.administrator.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x415ebc38) 解决方案 这信息也太少了... 解决方案二: 0.0,稍等 05-24 18:35:47.070 843-1911/? W/Temper

javaweb-Properties load报错 问题,求大神

问题描述 Properties load报错 问题,求大神 Properties报错,但是当我加入Sun JDK1.6时候就不报错了,为什么呢? 解决方案 感觉要加异常处理,不懂为什么 解决方案二: 加入sun JDK1.6包,就行了呢,为什么

java cmd报错!!求大神!

问题描述 java cmd报错!!求大神! 10C 该项目打包jar在cmd运行报错了.在idea工具下正常运行,请问什么原因啊!求大神指教!具体怎么解决啊!谢谢! 解决方案 activity -server.jar 包没导入吧,放到lib里边试试 解决方案二: 配置文件里面有东西没配置好 解决方案三: http://chenzhou123520.iteye.com/blog/1971322是不是这个原因?

native-tomcat启动报错问题,求大神帮忙

问题描述 tomcat启动报错问题,求大神帮忙 Managed Threads: 3 Active Threads: 3 Active Tasks: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@189b939 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2) com.mchange.v2.resourcepool.BasicResourcePo