Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-13838

Regression: Shared EntityManager proxy insists on actualTransactiveActive flag even with SYNCHRONIZATION_NEVER

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 4.2.4
    • Fix Version/s: 4.2.5, 4.3 RC1
    • Component/s: Transaction
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      If set the transaction synchronization to be SYNCHRONIZATION_NEVER, e.g.:

          @Override
          public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
              if(bean instanceof AbstractPlatformTransactionManager){
                  AbstractPlatformTransactionManager transactionManager = (AbstractPlatformTransactionManager)bean;
                  transactionManager.setTransactionSynchronization(SYNCHRONIZATION_NEVER);
              }
              return bean;
          }
      

      I get a following exception when trying to save an object using jpa repository:

      Caused by: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call
      	at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:277)
      	at com.sun.proxy.$Proxy126.persist(Unknown Source)
      	at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:439)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:483)
      	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:483)
      	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:468)
      	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
      	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
      

      With that setup TransactionSynchronizationManager.setActualTransactionActive(status.hasTransaction()); is not called and now SharedEntityManagerCreator requires actual transaction to be active:

                                      if (target == null || !TransactionSynchronizationManager.isActualTransactionActive()) {
      					throw new TransactionRequiredException("No EntityManager with actual transaction available " +
      							"for current thread - cannot reliably process '" + method.getName() + "' call");
      				}
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              bikeholik Krzysztof Lewandowski
              Last updater:
              Spring Issues Spring Issues
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 24 weeks, 4 days ago