javax.persistence.TransactionRequiredException: no transaction is in progress

Stack Overflow | Praveen | 4 months ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    Hibernate 5.2.0 changed the method signature for Session.getFlushMode() so that it returns a javax.persistence.FlushModeType instead of a org.hibernate.FlushMode Spring 4.3.0 introduced several changes so that it could remain compatible with both 5.1.0 and 5.2.0 mainly by introducing indirection to obtain the Hibernate flush mode through SessionFactoryUtils.getFlushMode(session). However, this necessary change was omitted from SpringSessionSynchronization which still uses the following code snippet in beforeCommit(): if (!session.getFlushMode().equals(FlushMode.MANUAL)) { ... } which should now be: FlushMode flushMode = SessionFactoryUtils.getFlushMode(session); if (FlushMode.MANUAL.equals(flushMode)) { ... } This has critical consequences. Due to this bug, Spring 4.3.0 is not compatible with either Hibernate 5.1.0 nor 5.2.0 When using Hibernate 5.1.0 this bug causes a java.lang.NoSuchMethodError due to the method signature change: java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Ljavax/persistence/FlushModeType; at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:101) While in Hibernate 5.2.0 this causes javax.persistence.TransactionRequiredException due to equals(FlushMode.MANUAL) always returning false since it is comparing javax.persistence.FlushModeType vs org.hibernate.FlushMode javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3392) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1385) at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:104)

    Spring JIRA | 8 months ago | Manuel Dominguez Sarmiento
    javax.persistence.TransactionRequiredException: no transaction is in progress
  2. 0

    Hibernate 5.2.0 changed the method signature for Session.getFlushMode() so that it returns a javax.persistence.FlushModeType instead of a org.hibernate.FlushMode Spring 4.3.0 introduced several changes so that it could remain compatible with both 5.1.0 and 5.2.0 mainly by introducing indirection to obtain the Hibernate flush mode through SessionFactoryUtils.getFlushMode(session). However, this necessary change was omitted from SpringSessionSynchronization which still uses the following code snippet in beforeCommit(): if (!session.getFlushMode().equals(FlushMode.MANUAL)) { ... } which should now be: FlushMode flushMode = SessionFactoryUtils.getFlushMode(session); if (FlushMode.MANUAL.equals(flushMode)) { ... } This has critical consequences. Due to this bug, Spring 4.3.0 is not compatible with either Hibernate 5.1.0 nor 5.2.0 When using Hibernate 5.1.0 this bug causes a java.lang.NoSuchMethodError due to the method signature change: java.lang.NoSuchMethodError: org.hibernate.Session.getFlushMode()Ljavax/persistence/FlushModeType; at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:101) While in Hibernate 5.2.0 this causes javax.persistence.TransactionRequiredException due to equals(FlushMode.MANUAL) always returning false since it is comparing javax.persistence.FlushModeType vs org.hibernate.FlushMode javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3392) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1385) at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:104)

    Spring JIRA | 8 months ago | Manuel Dominguez Sarmiento
    javax.persistence.TransactionRequiredException: no transaction is in progress
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Proper way to configure Spring transaction manager on a multi-datasource scenario (hibernate 5.2.6)

    Stack Overflow | 3 weeks ago | tggm
    javax.persistence.TransactionRequiredException: no transaction is in progress
  5. 0

    camel-jpa "no transaction is in progress"

    Stack Overflow | 5 months ago | dermoritz
    javax.persistence.TransactionRequiredException: no transaction is in progress

    2 unregistered visitors

    Root Cause Analysis

    1. javax.persistence.TransactionRequiredException

      no transaction is in progress

      at org.hibernate.internal.SessionImpl.checkTransactionNeeded()
    2. Hibernate
      SessionImpl.flush
      1. org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3393)
      2. org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1386)
      2 frames
    3. org.springframework.orm
      SpringSessionSynchronization.beforeCommit
      1. org.springframework.orm.hibernate5.SessionFactoryUtils.flush(SessionFactoryUtils.java:144)
      2. org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:95)
      2 frames
    4. Spring Tx
      TransactionInterceptor.invoke
      1. org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
      2. org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:932)
      3. org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:744)
      4. org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
      5. org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:487)
      6. org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
      7. org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
      7 frames
    5. Spring AOP
      CglibAopProxy$DynamicAdvisedInterceptor.intercept
      1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      2. org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
      3. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      4. org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
      4 frames
    6. my.pkg.entity
      StoreImpl$$EnhancerBySpringCGLIB$$73283c3f.merge
      1. my.pkg.entity.impl.StoreImpl$$EnhancerBySpringCGLIB$$73283c3f.merge(<generated>)
      1 frame
    7. my.pkg.controller
      LoginController$$FastClassBySpringCGLIB$$d71b2e05.invoke
      1. my.pkg.controller.LoginController.setClient(LoginController.java:243)
      2. my.pkg.controller.LoginController.setupUserSession(LoginController.java:185)
      3. my.pkg.controller.LoginController.login(LoginController.java:121)
      4. my.pkg.controller.LoginController$$FastClassBySpringCGLIB$$d71b2e05.invoke(<generated>)
      4 frames
    8. Spring Core
      MethodProxy.invoke
      1. org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      1 frame
    9. Spring AOP
      CglibAopProxy$DynamicAdvisedInterceptor.intercept
      1. org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:651)
      1 frame
    10. my.pkg.controller
      LoginController$$EnhancerBySpringCGLIB$$442b15b7.login
      1. my.pkg.controller.LoginController$$EnhancerBySpringCGLIB$$442b15b7.login(<generated>)
      1 frame
    11. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:497)
      4 frames
    12. Spring
      InvocableHandlerMethod.invokeForRequest
      1. org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
      2. org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
      2 frames
    13. Spring MVC
      FrameworkServlet.doPost
      1. org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
      2. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
      3. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
      4. org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
      5. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
      6. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
      7. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
      8. org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
      8 frames