Announcement Announcement Module
Collapse
No announcement yet.
Cannot get In-Memory Repository to work! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot get In-Memory Repository to work!

    I am using 2.1.7.RELEASE of Spring Batch and I am trying to get the In-Memory repository to work but I'm getting transaction errors and I can't figure out why. My job run to completion without error, but at the end of the run it looks like Spring Batch is trying to commit something and it's throwing hibernate exceptions. Here is my batch configuration and the stack traces.

    Anyone have any ideas how to resolve this?

    Code:
    	<bean id="jobRepository"
    		class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
    		<property name="isolationLevelForCreate" value="ISOLATION_REPEATABLE_READ"/>
    		<property name="transactionManager" ref="jobTransactionManager"/>
    	</bean>
    
    	<bean id="jobTransactionManager"
    		class="org.springframework.batch.support.transaction.ResourcelessTransactionManager">
    	</bean>
    
    	<bean id="jobLauncher"
    		class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    		<property name="jobRepository" ref="jobRepository" />
    	</bean>
    Here are the stack traces.

    Code:
    org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:660)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:147)
    	at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:264)
    	at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
    	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
    	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
    	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
    	at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:250)
    	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
    	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
    	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
    	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
    	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
    	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
    	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
    	at org.bjc.med.importer.main.Main.process(Main.java:86)
    	at org.bjc.med.importer.main.Main.<init>(Main.java:55)
    	at org.bjc.med.importer.main.Main.main(Main.java:19)
    Caused by: org.hibernate.TransactionException: Transaction not successfully started
    	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:100)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
    	... 23 more
    2011-08-15 15:38:02,730 ERROR [AbstractStep] Encountered an error saving batch meta data. This job is now in an unknown state and should not be restarted.
    org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=4 with wrong version (1), where current version is 2
    	at org.springframework.batch.core.repository.dao.MapStepExecutionDao.updateStepExecution(MapStepExecutionDao.java:98)
    	at org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:171)
    	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:244)
    	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
    	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
    	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
    	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
    	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
    	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
    	at org.bjc.med.importer.main.Main.process(Main.java:86)
    	at org.bjc.med.importer.main.Main.<init>(Main.java:55)
    	at org.bjc.med.importer.main.Main.main(Main.java:19)
    2011-08-15 15:38:02,730 ERROR [AbstractJob] Encountered interruption executing job
    org.springframework.batch.core.JobInterruptedException: Step requested termination: StepExecution: id=4, version=1, name=stage, status=UNKNOWN, exitStatus=UNKNOWN, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=1, exitDescription=org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:660)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:147)
    	at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:264)
    	at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
    	at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
    	at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
    	at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
    	at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:250)
    	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
    	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
    	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
    	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
    	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
    	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
    	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
    	at org.bjc.med.importer.main.Main.process(Main.java:86)
    	at org.bjc.med.importer.main.Main.<init>(Main.java:55)
    	at org.bjc.med.importer.main.Main.main(Main.java:19)
    Caused by: org.hibernate.TransactionException: Transaction not successfully started
    	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:100)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
    	... 23 more
    
    	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:67)
    	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
    	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
    	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
    	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48)
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
    	at org.bjc.med.importer.main.Main.process(Main.java:86)
    	at org.bjc.med.importer.main.Main.<init>(Main.java:55)
    	at org.bjc.med.importer.main.Main.main(Main.java:19)

  • #2
    Try changing the name of the bean from "jobTransactionManager" to "transactionManager"

    Code:
    	<bean id="jobRepository"
    		class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
    		<property name="isolationLevelForCreate" value="ISOLATION_REPEATABLE_READ"/>
    		<property name="transactionManager" ref="transactionManager"/> 
    	</bean>
    
    	<bean id="transactionManager"
    		class="org.springframework.batch.support.transaction.ResourcelessTransactionManager">
    	</bean>

    Comment


    • #3
      I have a similar configuration, though without the isolationLevelForCreate property set. What kind of job configuration do you have - do you have any JDBC Item readers or writers?

      Comment


      • #4
        Changing the bean's name to to "transactionManager" will not work. I first had it named "transactionManager" and still got stack traces at the end of the job however the stack traces had different errors than the ones posted aboved. I tracked this down to the fact that I already have a "transactionManager" bean defined in another spring configuration file from a shared project of DAO code which configures hibernate for the DAOs. So I did not want a "transactionManager" naming conflict and even when the two were the same Spring Batch still stack traced at the end of the job.

        Comment


        • #5
          My job is very simple. To does not use any readers or writers however it does use a shared project of DAO code which is configured (by spring configuration files) to use hibernate to access the database. I use the ExecutionContext to pass data from one step to the next. Overall the steps of the job are:

          1) Configure yourself
          2) Get data file
          3) Parse data file
          4) Persist data to database.

          These steps run without error and run correctly and I see the data persisted to the database. But when all the steps are complete and Spring Batch is done running the job that is when (I think) Spring Batch is trying to persist something and this causes Spring Batch to stack trace.

          Here is some additional information I can share which may help....

          If I run my job and I COMMENT OUT the section of my code which uses the shared project DAO's to PERSIST data to the database, then Spring Batch DOES NOT stack trace and I HAVE 100% VERIFIED THE DAO CODE IS NOT THROWING AN EXCEPTION. However, if I run my job and execute the the DAO code to persist the data to the database, then Spring Batch stack traces when the job is finished. This behavior is very strange.

          Here is the configuration of my job.

          Code:
             	<batch:job id="Job-01">              	
             	    <batch:step id="load01" next="sftp01">
          			<batch:tasklet>
          				<bean parent="loadConfigTasklet">
          					<property name="config" value="/abcdefg.xml"/>
          				</bean>
          			</batch:tasklet>
          		</batch:step>
          		<batch:step id="sftp01" next="read01">
          		    <batch:tasklet ref="sftpFileTasklet"/>
          		</batch:step>		
          		<batch:step id="read01" next="stage01">
                    <batch:tasklet ref="readFileTasklet" />
                  </batch:step>
                  <batch:step id="stage01">
                    <batch:tasklet ref="stagingTasklet" />
                  </batch:step>
          	</batch:job>
          Last edited by mjremijan; Aug 16th, 2011, 09:53 AM.

          Comment


          • #6
            Originally posted by mjremijan View Post
            Changing the bean's name to to "transactionManager" will not work. I first had it named "transactionManager" and still got stack traces at the end of the job however the stack traces had different errors than the ones posted aboved. I tracked this down to the fact that I already have a "transactionManager" bean defined in another spring configuration file from a shared project of DAO code which configures hibernate for the DAOs. So I did not want a "transactionManager" naming conflict and even when the two were the same Spring Batch still stack traced at the end of the job.
            I don't know why but I do know from experience that spring batch's transaction manager must be named "transactionManager" as I stated above. If you have another transaction manager defined elsewhere try changing that beans name to something else instead of "transactionManager". That'll ensure that you don't have the naming conflict.

            Comment

            Working...
            X