Announcement Announcement Module
Collapse
No announcement yet.
Transaction handling in the listeners Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction handling in the listeners

    I would appreciate any clarification on how the transaction will work for the following scenario. (Using 1.1.1.RELEASE)

    Case-1
    -StepListener afterJob() has DAO-1 and DAO-2 for inserting data into two different tables in that sequence (Using the same datasource, JdbcTemplate and DataSourceTransactionManager)
    -I would like DAO-1 to rollback if DAO-2 fails.
    -Do i need to use transaction attributes such as REQUIRES_NEW for the afterJob() method? What are the alternatives?
    -Does it work the same way for StepListener, JobListener and Tasklet?

    Case-2
    -Reading from a file
    -For each read, i am writing the file data into table A and few messages into table B by using the composite writer.
    -Record got inserted into Table A.
    -I would like table A insert to rollback let's say for the primary key failure for table B.
    -Would spring batch handle this by default?

    When exactly does spring batch handles transactions by itself? (Assuming that i am using the same datasource, JdbcTemplate and DataSourceTransactionManager )

    Thank you in advance!
    Last edited by springforever; Mar 19th, 2009, 02:11 PM. Reason: typo

  • #2
    Spring Batch wraps a chunk of items inside a step in a transaction (the commitInterval in the *StepFactoryBeans determine how many items); so that means calls to ItemReader, ItmemWriter, the Item*Listeners and the ChunkListener. All calls to the JobRepository are also transactional by default. Everything else you need to handle yourself.

    Comment

    Working...
    X