首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

org.hibernate.ObjectNotFoundException: No row with the given identifier exists

2012-09-14 
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:异常代码如下:org.hib

org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
异常代码如下:

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.clinic.model.Person#0]org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:435)org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:189)org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:178)org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)com.clinic.model.Person_$$_javassist_1.toString(Person_$$_javassist_1.java)java.lang.String.valueOf(String.java:2827)java.lang.StringBuilder.append(StringBuilder.java:115)com.clinic.dao.PersonDAOImpl.queryByID(PersonDAOImpl.java:123)com.clinic.service.PersonServiceImpl.addPerson(PersonServiceImpl.java:26)com.clinic.action.PersonAction.add(PersonAction.java:26)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)java.lang.reflect.Method.invoke(Method.java:597)com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)


之前都没有报这个异常,修改一些代码后,后来在注册的时候报了这个异常
经检查后,发现PersonDAOImpl中,用system.out.println中有load了
注册的时候,不能有load,要用get,哪怕是在打印中也不能
然后我把打印注释了就正常了

问题代码如下:
public Person queryByID(int id) {System.out.println("queryByID1*****" + (Person) this.getHibernateTemplate().get(Person.class, id));System.out.println("queryByID2*****" +  this.getHibernateTemplate().get(Person.class, id));System.out.println("queryByID3*****" +  this.getHibernateTemplate().load(Person.class, id));System.out.println("queryByID4*****" +  (Person) this.getHibernateTemplate().load(Person.class, id));return (Person) this.getHibernateTemplate().get(Person.class, id);}


修改后为:
public Person queryByID(int id) {System.out.println("queryByID1*****" + (Person) this.getHibernateTemplate().get(Person.class, id));System.out.println("queryByID2*****" +  this.getHibernateTemplate().get(Person.class, id));//System.out.println("queryByID3*****" +  this.getHibernateTemplate().load(Person.class, id));//System.out.println("queryByID4*****" +  (Person) this.getHibernateTemplate().load(Person.class, id));return (Person) this.getHibernateTemplate().get(Person.class, id);}


这个再一次说明了,get和load的区别

热点排行