Announcement Announcement Module
Collapse
No announcement yet.
Spring batch with Hibernate commit problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring batch with Hibernate commit problem

    Hi all,

    I have used spring batch 2.0 with Hibernate 3.0.
    Now in job configuration I have used the commit-interval 5 in Spring batch.
    In hibernate I have not used any commit method.
    So while hibernate tries to commit after its work is done it is giving below exception because Spring Batch also tries to commit.Want to get rid of this.
    I am confused how do I configure Spring batch with hibernate so that I can not get the below exeption.
    Please help.

    18:20:42,974 DEBUG org.springframework.batch.core.launch.support.Comm andLineJobRunner.main() TaskletStep:66 - Applyin
    g contribution: [StepContribution: read=1, written=1, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStat
    us=EXECUTING]
    18:20:44,646 ERROR org.springframework.batch.core.launch.support.Comm andLineJobRunner.main() TaskletStep:108 - Rollba
    ck caused by fatal failure failed
    org.springframework.transaction.IllegalTransaction StateException: Transaction is already completed - do not call comm
    it or rollback more than once per transaction
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.rollback(AbstractPlatform Transa
    ctionManager.java:795)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.rollback(TaskletStep.java:368)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.access$1000(TaskletStep.java:68)
    at org.springframework.batch.core.step.tasklet.Taskle tStep$2.doInChunkContext(TaskletStep.java:309)
    at org.springframework.batch.core.scope.context.StepC ontextRepeatCallback.doInIteration(StepContextRepe atCall
    back.java:67)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:367)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:214)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.doExecute(TaskletStep.java:239)
    at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:197)
    at org.springframework.batch.core.job.AbstractJob.han dleStep(AbstractJob.java:348)
    at org.springframework.batch.core.job.flow.FlowJob.ac cess$100(FlowJob.java:43)
    at org.springframework.batch.core.job.flow.FlowJob$Jo bFlowExecutor.executeStep(FlowJob.java:137)
    at org.springframework.batch.core.job.flow.support.st ate.StepState.handle(StepState.java:60)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.resume(SimpleFlow.java:144)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.start(SimpleFlow.java:124)
    at org.springframework.batch.core.job.flow.FlowJob.do Execute(FlowJob.java:105)
    at org.springframework.batch.core.job.AbstractJob.exe cute(AbstractJob.java:250)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:110)
    at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:105)
    at org.springframework.batch.core.launch.support.Comm andLineJobRunner.start(CommandLineJobRunner.java:2 07)
    at org.springframework.batch.core.launch.support.Comm andLineJobRunner.main(CommandLineJobRunner.java:25 4)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJava Mojo.java:271)
    at java.lang.Thread.run(Thread.java:595)


    job.xml:-
    Code:
    ....
    <job id="counterJob">
    		<step id="fetchRecord" >
    			<tasklet>
    				<chunk reader="inputMemberSource" processor="process" writer="opWriter" commit-interval="0">					
    				</chunk>
    				<listeners>
    	            	<listener ref="stepListener"/>
    	        	</listeners>
    				
    			</tasklet>
    		</step>				
    	</job>
    ....
    Dao class:-

    Code:
    Query query = session.createSQLQuery("update TEST SET ID = '999'");
    		query.executeUpdate();

  • #2
    @kousik.majumder,

    Originally posted by kousik.majumder View Post
    So while hibernate tries to commit after its work is done
    Hibernate does not commit anything, the most it does it flushes ( syncs data in memory with a database ), where when it flushes would depend on a flush mode. The exception above means that that you are trying to commit explicitly before the control goes back to the Spring Batch.

    /Anatoly

    Comment

    Working...
    X