Announcement Announcement Module
No announcement yet.
Spring batch with Hibernate commit problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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 andLineJobRunner.main() TaskletStep:66 - Applyin
    g contribution: [StepContribution: read=1, written=1, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStat
    18:20:44,646 ERROR 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 atformTransactionManager.rollback(AbstractPlatform Transa
    at org.springframework.batch.core.step.tasklet.Taskle tStep.rollback(
    at org.springframework.batch.core.step.tasklet.Taskle tStep.access$1000(
    at org.springframework.batch.core.step.tasklet.Taskle tStep$2.doInChunkContext(
    at org.springframework.batch.core.scope.context.StepC ontextRepeatCallback.doInIteration(StepContextRepe atCall
    at plate.getNextResult(
    at plate.executeInternal(
    at plate.iterate(
    at org.springframework.batch.core.step.tasklet.Taskle tStep.doExecute(
    at org.springframework.batch.core.step.AbstractStep.e xecute(
    at org.springframework.batch.core.job.AbstractJob.han dleStep(
    at cess$100(
    at org.springframework.batch.core.job.flow.FlowJob$Jo bFlowExecutor.executeStep(
    at ate.StepState.handle(
    at mpleFlow.resume(
    at mpleFlow.start(
    at Execute(
    at org.springframework.batch.core.job.AbstractJob.exe cute(
    at leJobLauncher$
    at org.springframework.core.task.SyncTaskExecutor.exe cute(
    at andLineJobRunner.start( 07)
    at andLineJobRunner.main( 4)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
    at java.lang.reflect.Method.invoke(
    at org.codehaus.mojo.exec.ExecJavaMojo$

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

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

  • #2

    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.