Announcement Announcement Module
Collapse
No announcement yet.
'no transaction is in progress' exception in light of parallel mode flush workaround. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • '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.

  • #2
    please post the source of the test class, if you use an @TestExecutionerListeners annotation, you need to provide the TransactionalTestExecutionListener by hand, normally it is set by default from SpringJUnit4ClassRunner

    Comment


    • #3
      I do not use @TestExecutionerListener explicitly, the test is simply:

      Code:
      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration(locations = {"..."})
      @Configurable
      public class Test {
      
          @Autowired
          private JobLauncher launcher;
      
          @Autowired
          private Job job;
      
          @Test
          public void testParallel() throws Exception {
      			
                  Map<String, JobParameter> jps = new HashMap<String, JobParameter>();
                  jps.put("input.file", new JobParameter(activeTestFilePath));
                  jps.put("now", new JobParameter(new Date()));
                  JobParameters jobParameters = new JobParameters(jps);
                  JobExecution exec = launcher.run(job, jobParameters);
      
                  assertEquals("Job execution contained errors: " + exec.getAllFailureExceptions(), 0, exec.getAllFailureExceptions().size());
      	}
      	
      }

      Comment


      • #4
        see stackoverflow.com: springjpa-transactional-not-committing

        Note the mode="aspectj" in your configuration. It requires additional configuration and usually you shouldn't use it unless you understand what does it mean and why do you need it. See 10.5.6 Using @Transactional.

        Comment

        Working...
        X