'no transaction is in progress' exception in light of parallel mode flush workaround.
I'm caught with the lesser of two evils (https://jira.springsource.org/browse/BATCH-1767 and https://jira.springsource.org/browse/SPR-5082), and I'm hoping you can help me.
I am using Spring Batch in parallel mode with Roo-generated entities, and must call
Code:
Entity.entityMan.entityManager().flush();
at the end of the write method in my ItemWriter, to avoid the problems highlighted in https://jira.springsource.org/browse/BATCH-1767.
This works fine when running from Tomcat.
In tests, running from mvn, I have a test annotated with @RunWith(SpringJUnit4ClassRunner.class), @ContextConfiguration(...) and @Configurable, with the JobLauncher and Job instances autowired. "
Code:
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
" is specified, as stated in https://jira.springsource.org/browse/SPR-5082.
However, I still encounter the following exception:
Code:
org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:306)
at org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc$afterThrowing$org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspect$1$18a1ac9(JpaExceptionTranslatorAspect.aj:15)
...
Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:792)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
at $Proxy72.flush(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
at $Proxy72.flush(Unknown Source)
I'm using Spring 3.0.5.RELEASE and Spring Batch 2.1.8.RELEASE.
I'd like to be able to run both in Tomcat and in tests with the same configuration - can you help?
Thanks,
Graham.