Announcement Announcement Module
Collapse
No announcement yet.
JdbcBatchItemWriter and transaction rallback Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JdbcBatchItemWriter and transaction rallback

    Hello All,

    I'm using RC2 and seem to have problems with processing exceptions during db insert.
    I have 5 files with one record in each, they are retrieved and passed to JdbcBatchItemWriter. The exception, configured as skippable is thrown during the db commit (one file contains error). I would expect that transaction will be rolled back and there will be no new records in db. Instead in the listener @AfterWrite I see that all items are processed again one by one, and 4 out of 5 records end up in the database. Now, in RC1 @AfterWrite was called as well, but no records where actually added to DB. Is it new functionality or bug in RC2?
    HTML Code:
    	<job id="SpringBoard_AR_DD_Job">
    		<step id="load">
    			 <tasklet reader="SpringBoard_AR_DDItemReader" writer="SpringBoard_AR_DDItemWriter" commit-interval="${job.commit.interval}" skip-limit="10">
                     <skippable-exception-classes>
    			         org.springframework.dao.DataIntegrityViolationException
    			     </skippable-exception-classes>
    			</tasklet>               
    		    <listeners>
    		    	<listener ref="SpringBoard_AR_DDstepListener"/>
    		    </listeners>
    		    <fail on="FAILED" exit-code="EARLY TERMINATION"/>
    			<next on="COMPLETED WITH SKIPS" to="moveForRetry" />
    			<next on="*" to="moveToComplete" />
    		</step>
    	 <step id="moveForRetry" tasklet="SpringBoard_AR_DDretryMovingTasklet" next="moveToComplete"/>
    	 <step id="moveToComplete" tasklet="SpringBoard_AR_DDcompMovingTasklet"/>
    	</job>
    	<beans:bean id="SpringBoard_AR_DDItemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
    		<beans:property name="dataSource" ref="dataSource" />
            <beans:property name="itemPreparedStatementSetter">
    		   <beans:bean class="com.cce.filenet.reports.dao.SpringBoard_AR_DDPreparedItemSetter" />
    	    </beans:property>
            <beans:property name="sql" value="INSERT INTO SpringBoard_AR_Driver_Docs (DriverCode, DivisionNum, SalesBranch, DateSettled, ArchiveDate, UpdateStatus) VALUES (?,?,?,?,?,?)" />
    	</beans:bean>
    
    

  • #2
    The way that skips are processed was changed in RC2. So if the error was a DataIntegrityViolationException (which you said was skippable) then this is the expected behaviour. There should be a rollback as well, which will show up in your StepExecution meta data.

    Comment


    • #3
      Thank you Dave!

      I've tried to remove skippable exceptions from step definition but it didn't change the outcome : still 4 records where added to DB

      I've used to store list of file names and depending on result of database operation move those files into "completed" or "retry" folder. Apparently this approach doesn't work any more. Could you please advise the best way to address this requirement in new release?

      Regards,
      Igor

      Comment


      • #4
        What's the requirement? If you don't want to skip, then change the skip limit to 0.

        Comment


        • #5
          Thanks! By setting skip-limit=0 I'm getting functionality I needed - the batch is not committed second time.

          Regards,
          Igor

          Comment

          Working...
          X