-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Closed
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)type: bugA general bugA general bug
Milestone
Description
Krzysztof Lewandowski opened SPR-13838 and commented
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");
}
Affects: 4.2.4
Attachments:
- screenshot-1.png (119.53 kB)
- screenshot-2.png (222.84 kB)
Issue Links:
- Shared EntityManager should immediately throw TransactionRequiredException if no transaction in progress [SPR-11923] #16541 Shared EntityManager should immediately throw TransactionRequiredException if no transaction in progress
- Transaction propagation SUPPORTS leads to “HHH000326: Cannot join transaction” warning [SPR-13242] #17833 Transaction propagation SUPPORTS leads to “HHH000326: Cannot join transaction” warning
- Inconsistent JPA behavior using no transaction, propagation SUPPORTS and OpenEntityManager pattern [SPR-13243] #17834 Inconsistent JPA behavior using no transaction, propagation SUPPORTS and OpenEntityManager pattern
- Shared EntityManager's target lookup doesn't work with Spring Data's ChainedTransactionManager [SPR-14371] #18944 Shared EntityManager's target lookup doesn't work with Spring Data's ChainedTransactionManager
1 votes, 5 watchers
Metadata
Metadata
Assignees
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)type: bugA general bugA general bug