本文介绍了什么原因导致org.hibernate.PropertyAccessException:setter中发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 请求处理失败;嵌套异常是javax.persistence.PersistenceException:org.hibernate.PropertyAccessException:异常发生在my.Class的setter中 javax.persistence.PersistenceException:org.hibernate.PropertyAccessException:my.Class $ setter中发生异常b $ b 代码: @ManyToMany(fetch = FetchType.EAGER) public void setTags(Set> Tags> tags){ this.tags.clear(); (标签标签:标签) { addTag(标签); $ b public boolean addTag(final Tag tag){ if(tags.contains(tag)){ return假; } return tags.add(tag); 我在构造函数中初始化标签: tags = new HashSet< Tag>(); 编辑 方法: ax.persistence.PersistenceException:org.hibernate.PropertyAccessException:com.mycompany.domain.Book setter中发生异常.Tag at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)〜[hibernate-entitymanager-4.2.0.Final.jar:4.2.0.Final] at org。 hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:838)〜[hibernate-entitymanager-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl .java:781)〜[hibernate-entitymanager-4.2.0.Final.jar:4.2.0.Final] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:201304051638] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)〜[na:201304051638] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe在org.springframework中,在java.lang.reflect.Method.invoke(Method.java:601)〜[na:1.7.0]处。 orm.jpa.SharedEntityManagerCreator $ SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)〜[spring-orm-3.1.4.RELEASE.jar:3.1.4.RELEASE] at $ Proxy215.find(Unknown Source)〜 [na:na] at com.mycompany.persistence.BookJpaRepository.get(BookJpaRepository.java:22)〜[classes /:na] at com.mycompany.service.BookService.getBook(BookService。 java:44)〜[classes /:na] at com.mycompany.service.BookService $$ FastClassByCGLIB $$ d6b91ae6.invoke(< generated>)〜[BookService $$ FastClassByCGLIB $$ d6b91ae6.class:na ] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)〜[spring-core-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org .springframework.aop.framework.CglibAopProxy $ CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)〜[spring-aop-3.2.1.RELEASE.jar:3.2.1.R ELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)〜[spring-aop-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.aop.framework org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)〜[spring-tx-3.2.1.RELEASE.jar:3.2.1.RELEASE] .ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)〜[spring-aop-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.aop.framework.CglibAopProxy $ DynamicAdvisedInterceptor.intercept( CglibAopProxy.java:631)〜[spring-aop-3.2.1.RELEASE.jar:3.2.1.RELEASE] at com.mycompany.service.BookService $$ EnhancerByCGLIB $$ e6a4e1a3.getBook(< generated> ;)〜[BookService $$ EnhancerByCGLIB $$ e6a4e1a3.class:na] at com.mycompany.rest.controller.BookController.getFeedbackForBook(BookController.java:106)〜[classes /:na] 在sun.reflect.NativeMethodAccessorImpl.invoke0(Native Met HOD)〜[NA:201304051638]在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57 )〜[NA:201304051638]在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java : 43)〜[na:201304051638] at org.springframework.web.method的java.lang.reflect.Method.invoke(Method.java:601)〜[na:1.7.0] 。 support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)〜[弹簧网络3.2.1.RELEASE.jar:3.2.1.RELEASE] 。在org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest (InvocableHandlerMethod.java:132)〜[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle( ServletInvocableHandlerMethod.java:104)〜[弹簧webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE]在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod (RequestMappingHandlerAdapter .jav a:745)〜[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java :686)〜[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 〜[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)〜[spring-webmvc-3.2 .1.RELEASE.jar:3.2.1.RELEASE] 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)〜[spring-webmvc-3.2.1.RELEASE.jar: 3.2.1.RELEASE] 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920)[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:816)[spring-webmvc-3.2.1.REL EASE.jar:3.2.1.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)[javax.servlet-api.jar:3.0.1] at org .springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801)[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] ,位于javax.servlet.http.HttpServlet.service (HttpServlet.java:770)[javax.servlet-api.jar:3.0.1] 在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)[web-core.jar: at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)[web-core.jar:3.1.2.1-SNAPSHOT] at org.apache .catalina.core.StandardContextValve .__ invoke(StandardContextValve.java:175)[web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)[ web-core.jar:3.1.2.1-SNAPSHOT] 在org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)[web-core.jar:3.1.2.1-SNAPSHOT] 在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)[web-core.jar:3.1.2.1-SNAPSHOT] 在org.apache.catalina.core.StandardHostValve .__ invoke (StandardHostValve.java:161)[web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)[web-core.jar:3.1。 2.1-SNAPSHOT] 在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)[web-core.jar:3.1.2.1-SNAPSHOT] 在org.apache.catalina .connector.CoyoteAdapter.service(CoyoteAdapter.java:231)[web-core.jar:3.1.2.1-SNAPSHOT] at com.sun.enterprise.v3.services.impl.ContainerMapper $ AdapterCallable.call(ContainerMapper .java:317)[kernel.jar:3.1.2.1-SNAPSHOT] at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)[kernel.jar:3.1。 2.1-SNAPSHOT] at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)[grizzly-http.jar:1.9.50] at com.su $ gbbb.ProcessorTask.doProcess(ProcessorTask.java:757)[grizzly-http.jar:1.9.50] at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) [grizzly-http.jar:1.9.50] at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)[grizzly-http.jar:1.9.50] at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)[grizzly-framework.jar:1.9.50] at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)[grizzly -framework.jar:1.9.50] at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)[grizzly-framework.jar:1.9.50] at com.sun。 grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)[灰色-http.jar:50年9月1日] 。在com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)[格筛的框架.jar:1.9.50] at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextT ask.java:59)[grizzly-framework.jar:1.9.50] at com.sun.grizzly.ContextTask.run(ContextTask.java:71)[grizzly-framework.jar:1.9.50] at com.sun.grizzly.util.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:532)[grizzly-utils.jar:1.9.50] at com.sun.grizzly.util.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:513)[grizzly-utils.jar:1.9.50] at java.lang.Thread.run(Thread.java:722)[na:1.7.0] 引起:org.hibernate.PropertyAccessException:异常发生在com.mycompany.domain.Book.Tags setter中$ or $ $ b $ org.hibernate.property.BasicPropertyAccessor $ BasicSetter.set(BasicPropertyAccessor.java:88)〜[hibernate -core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:710)〜[hibernate-core-4.2.0。 Final.jar:4.2.0.Final] 在org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:371)〜[hibernate-core-4.2.0 .Final.jar:4.2.0.Final] at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4499)〜[hibernate-core-4.2.0.Final.jar:4.2。 0.Final] at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:185)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] 在org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:137)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] 在org.hibernate.loader .Loader.initializeEntitiesAndCollections(Loader.java:1103)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.Loader.processResultSet(Loader.java: 960)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] 在org.hibernate.loader.Loader.doQuery(Loader.java:910)〜[hibernate-core-4.2 .0.Final.jar:4.2.0.Final] 在org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)〜[hibernate-core-4.2.0.Final.jar:4.2。 0.Final] org。 hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:311)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.Loader.loadEntity(Loader .java:2111)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)〜[ hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)〜[hibernate-core-4.2.0 .Final.jar:4.2.0.Final] at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3917)〜[hibernate-core-4.2.0.Final.jar:4.2。 0.Final] 在org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:460)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] 在org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:429)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] $ b $ org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:206)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] $ b $ org.hibernate。 event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:262)〜[休眠核-4.2.0.Final.jar:4.2.0.Final] 。在org.hibernate.event.internal.DefaultLoadEventListener.onLoad (DefaultLoadEventListener.java:150)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1091)〜[ hibernate-core-4.2.0.Final.jar:4.2.0.Final] 在org.hibernate.internal.SessionImpl.access $ 2000(SessionImpl.java:174)〜[hibernate-core-4.2.0。 Final.jar:4.2.0.Final] at org.hibernate.internal.SessionImpl $ IdentifierLoadAccessImpl.load(SessionImpl.java:2473)〜[hibernate-core-4.2.0.Final.jar:4.2.0 .final] 在org.hibernate.internal.SessionImpl.get(SessionImpl.java:987)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org .hibe rnate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:807)〜[hibernate-entitymanager-4.2.0.Final.jar:4.2.0.Final] ... 61个常用框架省略引起由:java.lang.reflect.InvocationTargetException:空。在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)〜[NA:201304051638]在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java : (方法57)〜[na:201304051638] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:201304051638] at java.lang.reflect.Method.invoke(Method。 java:601)〜[na:1.7.0] 在org.hibernate.property.BasicPropertyAccessor $ BasicSetter.set(BasicPropertyAccessor.java:65)〜[hibernate-core-4.2.0.Final.jar:4.2 .0.Final] ... 85个常用框架省略由java.lang.NullPointerException引起:$ b $ org.hibernate.engine.internal.StatefulPersistenceContext.getLoadedCollectionOwnerOrNull(StatefulPersistenceContext.java :8 59)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.event.spi.AbstractCollectionEvent.getLoadedOwnerOrNull(AbstractCollectionEvent.java:75)〜[hibernate-core -4.2.0.Final.jar:4.2.0.Final] at org.hibernate.event.spi.InitializeCollectionEvent。< init>(InitializeCollectionEvent.java:36)〜[hibernate-core-4.2.0 .Final.jar:4.2.0.Final] 在org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1846)〜[hibernate-core-4.2.0.Final.jar:4.2.0。 在org.hibernate.collection.internal.AbstractPersistentCollection $ 4.doWork(AbstractPersistentCollection.java:549)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] 在org.hibernate.collection上的org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:234)〜[hibernate-core-4.2.0.Final.jar:4.2.0.Final] 。 internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:545)〜[hibernate-co重新4.2.0.Final.jar:4.2.0.Final] 在org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:124)〜[hibernate-core-4.2.0.Final .jar:4.2.0.Final] 在org.hibernate.collection.internal.PersistentSet.iterator(PersistentSet.java:180)〜[hibernate-core-4.2.0.Final.jar:4.2.0。最终] 在com.mycompany.domain.Book.setTags(Book.java:185)〜[classes /:na] ... 90个常见框架省略 这就是为什么我更喜欢使用属性访问的字段访问(即将所有映射注释放在字段而不是getter上)。当用普通代码调用方法时,你想创建一个传递集合的副本,但当Hibernate本身调用setter时你不想这样做:它完全打破了懒加载。 What cause this exception, I can't manage to find out.Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Exception occurred inside setter of my.ClassRoot cause:javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Exception occurred inside setter of my.ClassCode:@ManyToMany(fetch = FetchType.EAGER)public void setTags(Set<Tags> tags) { this.tags.clear(); for (Tag tag : tags) { addTag(tag); }}public boolean addTag(final Tag tag) { if (tags.contains(tag)) { return false; } return tags.add(tag);}I initalize tags in the constructor:tags = new HashSet<Tag>();EDITException from logging in setter method:ax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Exception occurred inside setter of com.mycompany.domain.Book.Tags at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387) ~[hibernate-entitymanager-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:838) ~[hibernate-entitymanager-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:781) ~[hibernate-entitymanager-4.2.0.Final.jar:4.2.0.Final] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:201304051638] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:201304051638] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:201304051638] at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0] at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) ~[spring-orm-3.1.4.RELEASE.jar:3.1.4.RELEASE] at $Proxy215.find(Unknown Source) ~[na:na] at com.mycompany.persistence.BookJpaRepository.get(BookJpaRepository.java:22) ~[classes/:na] at com.mycompany.service.BookService.getBook(BookService.java:44) ~[classes/:na] at com.mycompany.service.BookService$$FastClassByCGLIB$$d6b91ae6.invoke(<generated>) ~[BookService$$FastClassByCGLIB$$d6b91ae6.class:na] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698) ~[spring-aop-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) ~[spring-aop-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) ~[spring-tx-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631) ~[spring-aop-3.2.1.RELEASE.jar:3.2.1.RELEASE] at com.mycompany.service.BookService$$EnhancerByCGLIB$$e6a4e1a3.getBook(<generated>) ~[BookService$$EnhancerByCGLIB$$e6a4e1a3.class:na] at com.mycompany.rest.controller.BookController.getFeedbackForBook(BookController.java:106) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:201304051638] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:201304051638] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:201304051638] at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0] at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) ~[spring-web-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) ~[spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:920) [spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:816) [spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:668) [javax.servlet-api.jar:3.0.1] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:801) [spring-webmvc-3.2.1.RELEASE.jar:3.2.1.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:770) [javax.servlet-api.jar:3.0.1] at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550) [web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) [web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:175) [web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java) [web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) [web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) [web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:161) [web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java) [web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) [web-core.jar:3.1.2.1-SNAPSHOT] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) [web-core.jar:3.1.2.1-SNAPSHOT] at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) [kernel.jar:3.1.2.1-SNAPSHOT] at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) [kernel.jar:3.1.2.1-SNAPSHOT] at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) [grizzly-http.jar:1.9.50] at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) [grizzly-http.jar:1.9.50] at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) [grizzly-http.jar:1.9.50] at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) [grizzly-http.jar:1.9.50] at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) [grizzly-framework.jar:1.9.50] at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) [grizzly-framework.jar:1.9.50] at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) [grizzly-framework.jar:1.9.50] at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) [grizzly-http.jar:1.9.50] at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) [grizzly-framework.jar:1.9.50] at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) [grizzly-framework.jar:1.9.50] at com.sun.grizzly.ContextTask.run(ContextTask.java:71) [grizzly-framework.jar:1.9.50] at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) [grizzly-utils.jar:1.9.50] at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) [grizzly-utils.jar:1.9.50] at java.lang.Thread.run(Thread.java:722) [na:1.7.0]Caused by: org.hibernate.PropertyAccessException: Exception occurred inside setter of com.mycompany.domain.Book.Tags at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:88) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:710) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:371) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4499) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:185) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:137) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1103) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.Loader.processResultSet(Loader.java:960) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.Loader.doQuery(Loader.java:910) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:311) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.Loader.loadEntity(Loader.java:2111) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3917) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:460) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:429) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:206) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:262) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1091) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:174) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2473) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.internal.SessionImpl.get(SessionImpl.java:987) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:807) ~[hibernate-entitymanager-4.2.0.Final.jar:4.2.0.Final] ... 61 common frames omittedCaused by: java.lang.reflect.InvocationTargetException: null at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:201304051638] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:201304051638] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:201304051638] at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0] at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:65) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] ... 85 common frames omittedCaused by: java.lang.NullPointerException: null at org.hibernate.engine.internal.StatefulPersistenceContext.getLoadedCollectionOwnerOrNull(StatefulPersistenceContext.java:859) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.event.spi.AbstractCollectionEvent.getLoadedOwnerOrNull(AbstractCollectionEvent.java:75) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.event.spi.InitializeCollectionEvent.<init>(InitializeCollectionEvent.java:36) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1846) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:549) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:234) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:545) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:124) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at org.hibernate.collection.internal.PersistentSet.iterator(PersistentSet.java:180) ~[hibernate-core-4.2.0.Final.jar:4.2.0.Final] at com.mycompany.domain.Book.setTags(Book.java:185) ~[classes/:na] ... 90 common frames omitted 解决方案 My guess is that Hibernate calls your setter with its own implementation of Set (PersistentSet) which implements lazy-loading, and is not initialized yet when the setter is called. Since you call a method on this set, it makes the set load itself while already being in a loading phase, which puts Hibernate in an inconsistent state.That's why I prefer using field access over property access (i.e. put all the mapping annotations on fields rather than getters). You want to make a copy of the passed set when the method is called by "normal" code, but you don't want to do that when Hibernate itself calls the setter: it completely break lazy-loading. 这篇关于什么原因导致org.hibernate.PropertyAccessException:setter中发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-16 08:57