Reputation: 1756
I create a EntityListener to audit the specific entity. To store a history of status changes. I inject the beans with AutowireHelper. I get it here https://guylabs.ch/2014/02/22/autowiring-pring-beans-in-hibernate-jpa-entity-listeners/comment-page-1/
This works fine to inject the repositories, but to call any function of any repository, go back to AutowireHelper.autowire line.
This is my code, the EntityListener execute AutowireHelper.autowire and when it comes to "find" method returns to autowire line:
public class AuditListener {
@Inject
private UserRepository userRepository;
@Inject
private ConfigurationRepository configurationRepository;
@PreUpdate
public void preUpdate(Object object) {
//TODO: pre update
AutowireHelper.autowire(this, this.userRepository, this.configurationRepository);
//I need get bbdd entities
List<Configuracion> config = this.configurationRepository.findAll();
Foo foo = (Foo) object;
System.out.println("Foo updated: " + foo.getId());
}
}
My error:
Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction 12:43:25,291 INFO [stdout] (http-/0.0.0.0:8080-1) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 12:43:25,291 INFO [stdout] (http-/0.0.0.0:8080-1) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 12:43:25,291 INFO [stdout] (http-/0.0.0.0:8080-1) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 12:43:25,291 INFO [stdout] (http-/0.0.0.0:8080-1) at java.lang.reflect.Method.invoke(Method.java:601) 12:43:25,291 INFO [stdout] (http-/0.0.0.0:8080-1) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) 12:43:25,291 INFO [stdout] (http-/0.0.0.0:8080-1) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) 12:43:25,291 INFO [stdout] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) 12:43:25,291 INFO [stdout] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.doResolveHandlerMethodException(ExceptionHandlerExceptionResolver.java:362)|
Full trace:
14:01:35,393 ERROR [stderr] (http-/0.0.0.0:8080-1) org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction 14:01:35,398 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:526) 14:01:35,401 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757) 14:01:35,405 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726) 14:01:35,408 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:521) 14:01:35,412 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291) 14:01:35,415 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) 14:01:35,419 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,422 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 14:01:35,425 ERROR [stderr] (http-/0.0.0.0:8080-1) at com.sun.proxy.$Proxy195.save(Unknown Source) 14:01:35,428 ERROR [stderr] (http-/0.0.0.0:8080-1) at es.company.project.web.controller.foo.FooController.save(FooController.java:395) 14:01:35,431 ERROR [stderr] (http-/0.0.0.0:8080-1) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 14:01:35,434 ERROR [stderr] (http-/0.0.0.0:8080-1) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 14:01:35,436 ERROR [stderr] (http-/0.0.0.0:8080-1) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 14:01:35,437 ERROR [stderr] (http-/0.0.0.0:8080-1) at java.lang.reflect.Method.invoke(Method.java:601) 14:01:35,438 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) 14:01:35,439 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) 14:01:35,441 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) 14:01:35,442 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:775) 14:01:35,443 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705) 14:01:35,445 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) 14:01:35,446 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) 14:01:35,447 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) 14:01:35,449 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) 14:01:35,450 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869) 14:01:35,451 ERROR [stderr] (http-/0.0.0.0:8080-1) at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) 14:01:35,453 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) 14:01:35,454 ERROR [stderr] (http-/0.0.0.0:8080-1) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 14:01:35,455 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) 14:01:35,456 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) 14:01:35,458 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316) 14:01:35,459 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126) 14:01:35,460 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90) 14:01:35,462 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,463 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) 14:01:35,464 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,465 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122) 14:01:35,466 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,467 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) 14:01:35,468 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,469 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169) 14:01:35,471 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,472 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48) 14:01:35,473 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,474 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205) 14:01:35,475 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,476 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120) 14:01:35,477 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,478 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:120) 14:01:35,479 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 14:01:35,480 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,481 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) 14:01:35,482 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 14:01:35,483 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,484 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91) 14:01:35,485 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,486 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53) 14:01:35,487 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 14:01:35,488 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) 14:01:35,489 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213) 14:01:35,490 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176) 14:01:35,491 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) 14:01:35,492 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) 14:01:35,494 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) 14:01:35,495 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) 14:01:35,496 ERROR [stderr] (http-/0.0.0.0:8080-1) at es.company.project.web.filter.RefererManagerFilter.doFilter(RefererManagerFilter.java:41) 14:01:35,497 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) 14:01:35,498 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) 14:01:35,499 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.multipart.support.MultipartFilter.doFilterInternal(MultipartFilter.java:118) 14:01:35,500 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 14:01:35,501 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) 14:01:35,502 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) 14:01:35,503 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) 14:01:35,504 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 14:01:35,505 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) 14:01:35,507 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) 14:01:35,508 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) 14:01:35,509 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) 14:01:35,510 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) 14:01:35,511 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) 14:01:35,512 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) 14:01:35,513 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) 14:01:35,514 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) 14:01:35,515 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) 14:01:35,516 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) 14:01:35,517 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) 14:01:35,518 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) 14:01:35,519 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) 14:01:35,520 ERROR [stderr] (http-/0.0.0.0:8080-1) at java.lang.Thread.run(Thread.java:722) 14:01:35,521 ERROR [stderr] (http-/0.0.0.0:8080-1) Caused by: javax.persistence.RollbackException: Error while committing the transaction 14:01:35,522 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:92) 14:01:35,523 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517) 14:01:35,524 ERROR [stderr] (http-/0.0.0.0:8080-1) ... 87 more 14:01:35,526 ERROR [stderr] (http-/0.0.0.0:8080-1) Caused by: java.lang.RuntimeException: java.lang.StackOverflowError 14:01:35,527 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.event.ListenerCallback.invoke(ListenerCallback.java:56) 14:01:35,528 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:110) 14:01:35,529 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.event.EntityCallbackHandler.preUpdate(EntityCallbackHandler.java:95) 14:01:35,530 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.event.EJB3FlushEntityEventListener.invokeInterceptor(EJB3FlushEntityEventListener.java:65) 14:01:35,531 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:334) 14:01:35,533 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:285) 14:01:35,534 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:165) 14:01:35,535 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:230) 14:01:35,536 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:100) 14:01:35,537 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:61) 14:01:35,538 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1166) 14:01:35,539 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1223) 14:01:35,540 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) 14:01:35,541 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:268) 14:01:35,542 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.criteria.CriteriaQueryCompiler$3.getResultList(CriteriaQueryCompiler.java:254) 14:01:35,543 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:323) 14:01:35,544 ERROR [stderr] (http-/0.0.0.0:8080-1) at sun.reflect.GeneratedMethodAccessor127.invoke(Unknown Source) 14:01:35,545 ERROR [stderr] (http-/0.0.0.0:8080-1) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 14:01:35,546 ERROR [stderr] (http-/0.0.0.0:8080-1) at java.lang.reflect.Method.invoke(Method.java:601) 14:01:35,547 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:483) 14:01:35,548 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:468) 14:01:35,549 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440) 14:01:35,551 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,552 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) 14:01:35,553 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) 14:01:35,554 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) 14:01:35,555 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,556 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) 14:01:35,557 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,558 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:113) 14:01:35,560 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,561 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 14:01:35,562 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,563 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 14:01:35,564 ERROR [stderr] (http-/0.0.0.0:8080-1) at com.sun.proxy.$Proxy162.findAll(Unknown Source) 14:01:35,565 ERROR [stderr] (http-/0.0.0.0:8080-1) at es.company.project.service.foo.audit.AuditListener.preUpdate(AuditListener.java:35) 14:01:35,566 ERROR [stderr] (http-/0.0.0.0:8080-1) at sun.reflect.GeneratedMethodAccessor128.invoke(Unknown Source) 14:01:35,567 ERROR [stderr] (http-/0.0.0.0:8080-1) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 14:01:35,568 ERROR [stderr] (http-/0.0.0.0:8080-1) at java.lang.reflect.Method.invoke(Method.java:601) 14:01:35,569 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.event.ListenerCallback.invoke(ListenerCallback.java:48) 14:01:35,570 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.event.EntityCallbackHandler.callback(EntityCallbackHandler.java:110) 14:01:35,571 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.event.EntityCallbackHandler.preUpdate(EntityCallbackHandler.java:95) 14:01:35,572 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.event.EJB3FlushEntityEventListener.invokeInterceptor(EJB3FlushEntityEventListener.java:65) 14:01:35,573 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:334) 14:01:35,574 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:285) 14:01:35,575 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:165) 14:01:35,577 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:230) 14:01:35,578 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:100) 14:01:35,579 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:61) 14:01:35,580 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1166) 14:01:35,581 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1223) 14:01:35,582 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101) 14:01:35,583 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:268) 14:01:35,584 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.hibernate.ejb.criteria.CriteriaQueryCompiler$3.getResultList(CriteriaQueryCompiler.java:254) 14:01:35,585 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:323) 14:01:35,586 ERROR [stderr] (http-/0.0.0.0:8080-1) at sun.reflect.GeneratedMethodAccessor127.invoke(Unknown Source) 14:01:35,587 ERROR [stderr] (http-/0.0.0.0:8080-1) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 14:01:35,588 ERROR [stderr] (http-/0.0.0.0:8080-1) at java.lang.reflect.Method.invoke(Method.java:601) 14:01:35,589 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:483) 14:01:35,590 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:468) 14:01:35,591 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440) 14:01:35,592 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,593 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) 14:01:35,594 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) 14:01:35,595 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) 14:01:35,596 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,597 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) 14:01:35,598 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,599 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:113) 14:01:35,600 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,601 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 14:01:35,602 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 14:01:35,603 ERROR [stderr] (http-/0.0.0.0:8080-1) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) 14:01:35,604 ERROR [stderr] (http-/0.0.0.0:8080-1) at com.sun.proxy.$Proxy162.findAll(Unknown Source) 14:01:35,605 ERROR [stderr] (http-/0.0.0.0:8080-1) at es.company.project.service.foo.audit.AuditListener.preUpdate(AuditListener.java:35) ...
Upvotes: 1
Views: 3046
Reputation: 459
I have experienced example the same issue. The only thing that worked for me was disabling flush and then reenabling it.
Session session = entityManager.unwrap(Session.class);
session.setHibernateFlushMode(FlushMode.MANUAL);
// do your db stuff
session.setHibernateFlushMode(FlushMode.AUTO);
Upvotes: 3
Reputation: 1098
You have a transaction problem here :
1 - Your
AuditListener.preUpdate
is called.
2 - You call that
this.configurationRepository.findAll()
in there.
3 - spring goes into its repository to fetch elements, you can see it in the stacktrace :
org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll
4 - After fetching elements and returning from repository, hibernate this time, tries to flush
elements, you can again see it in the stack :
org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1166)
5 - While flushing elements, hibernate calls again your AuditListener.preUpdate
method --> back to number 1
That is the explanation. Now, why do you need to call some Repository method in a PreUpdate event ? can't you do that any other way ?
Upvotes: 5