Announcement Announcement Module
Collapse
No announcement yet.
org.springframework.transaction.InvalidIsolationLe velException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • org.springframework.transaction.InvalidIsolationLe velException

    Hello Everyone,

    I am new to Spring Batch. I have tried to create a simple job using the examples given in sample applications. I want to run it in a web container. But it seems that my job is not running due to InvalidIsolationLevelException. Whenever I run my test I get this exception.

    org.springframework.transaction.InvalidIsolationLe velException: Standard JPA does not support custom isolation levels - use a special JpaDialect for your JPA implementation

    These are set-up I have done to run my batch job:

    batchContext.xml
    -----------------

    <job id="job1" xmlns="http://www.springframework.org/schema/batch">
    <step id="step1" parent="simpleStep">
    <tasklet>
    <chunk reader="reader" writer="writer"/>
    </tasklet>
    </step>
    </job>

    <bean id="reader" class="com.mega.neo.batch.ExampleItemReader"/>
    <bean id="writer" class="com.mega.neo.batch.ExampleItemWriter" />

    <bean id="simpleStep"
    class="org.springframework.batch.core.step.item.Si mpleStepFactoryBean"
    abstract="true">
    <property name="transactionManager" ref="transactionManager" />
    <property name="jobRepository" ref="jobRepository" />
    <property name="startLimit" value="100" />
    <property name="commitInterval" value="1" />
    </bean>

    <aop:config>
    <aop:aspect id="moduleLogging" ref="logAdvice">
    <aop:after
    pointcut="execution( * org.springframework.batch.item.ItemWriter+.write(O bject)) and args(item)"
    method="doStronglyTypedLogging" />
    </aop:aspect>
    <aop:aspect ref="eventAdvice">
    <aop:before
    pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
    method="before" />
    <aop:after
    pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
    method="after" />
    <aop:after-throwing throwing="t"
    pointcut="execution( * org.springframework.batch..Step+.execute(..)) and args(stepExecution)"
    method="onError" />
    </aop:aspect>
    </aop:config>


    ApplicationContext.xml
    ----------------------

    <import resource="classpath:/META-INF/spring/batchContext.xml" />

    <bean id="jobLauncher" class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    <property name="taskExecutor" ref="executor" />
    </bean>

    <bean id="jobRepository" class="org.springframework.batch.core.repository.s upport.JobRepositoryFactoryBean"
    p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager"
    p:tablePrefix="batch_" />

    <bean id="logAdvice" class="com.mega.neo.batch.advice.ProcessorLogAdvic e" />

    <bean id="eventAdvice" class="com.mega.neo.batch.advice.StepExecutionAppl icationEventAdvice" />


    JobLauncherController.java
    --------------------------

    JobLauncher jobLauncher = (JobLauncher)context.getBean("jobLauncher");
    Job job = (Job)context.getBean("job1");

    logger.info(jobLauncher);
    logger.info(job);

    ExitStatus exitStatus = null;

    try {
    JobExecution jobExecution = jobLauncher.run(
    job,
    new JobParametersBuilder()
    .addDate("date", new Date())
    .toJobParameters()
    );

    exitStatus = jobExecution.getExitStatus();
    logger.info("status >>> "+exitStatus.getExitCode());
    }
    catch(JobExecutionAlreadyRunningException jobExecutionAlreadyRunningException) {
    logger.info("jobExecutionAlreadyRunningException") ;
    }
    catch(JobRestartException jobRestartException) {
    logger.info("jobRestartException");
    }
    catch(JobInstanceAlreadyCompleteException jobInstanceAlreadyCompleteException) {
    logger.info("jobInstanceAlreadyCompleteException") ;
    }
    catch(JobParametersInvalidException jobParametersInvalidException){
    logger.info("jobParametersInvalidException");
    }


    JobLauncherControllerTest
    -------------------------
    @Autowired
    private JobLauncherController controller;

    @Test
    public void testHandle(){

    controller.handle();

    }


    Can someone please tell me what I have missed out here?

    Thanks
    Sanjoy

  • #2
    we need to know more about your environment to diagnose the problem:
    - full stack trace of the InvalidIsolationLevelException
    - the configuration configuration of your JPA environment (provider, database, etc)

    Spring Batch uses the SERIALIZABLE isolation level to create job executions, this can the cause.

    and please, use [ CODE ] tags.

    Comment


    • #3
      Hello arno,

      Thank you very much for reply. I have managed to stop this exception by using the below configuration:

      Code:
      <bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean" 
          	p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" p:tablePrefix="BATCH_">
          	<property name="isolationLevelForCreate" value="ISOLATION_DEFAULT"/>
          </bean>
      I am using MySQL and Hibernate. Could you please tell me whether it is right configuration. Sorry for not using CODE tag.

      Thanks

      Comment


      • #4
        ok, so you got rid of the exception by loosening the isolation level (which is usually READ_COMMITTED by default). This is ok if you're not launching a same job (too) concurrently. You can get the full explanation about this setting here: http://static.springsource.org/sprin...rJobRepository

        Comment

        Working...
        X