Announcement Announcement Module
Collapse
No announcement yet.
When use the tasklet's transaction-manager attribute? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • When use the tasklet's transaction-manager attribute?

    Hello Guys

    I have mostly the follow configuration

    Code:
    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
       <property name="dataSource" ref="dataSource" />	   
    </bean>
    
    <batch:job-repository id="jobRepository"
     		              data-source="dataSource"
            	              transaction-manager="transactionManager"
    			      isolation-level-for-create="SERIALIZABLE"
    			      table-prefix="BATCH_"
    		                   />
    And

    Code:
    <import resource="classpath:/jobs/definitions/beans/job-*-beans.xml"/>
    
    <batch:job id="simpleErrorChunk0203ImportDataJob" 
    	        job-repository="jobRepository" 
    		> 
    		<batch:step id="clienteStep" > 
    			<batch:tasklet >
    				<batch:chunk reader="clienteErrorChunk0203FlatFileItemReader" 
    				             writer="clienteJdbcBatchWriter" 
    				             commit-interval="50"/>
    		        </batch:tasklet>		
    		</batch:step>
    </batch:job>
    I have the same behavior if I add:

    Code:
    <import resource="classpath:/jobs/definitions/beans/job-*-beans.xml"/>
    
    <batch:job id="simpleErrorChunk0203ImportDataJob" 
    	        job-repository="jobRepository" 
    		> 
    		<batch:step id="clienteStep" > 
    			<batch:tasklet transaction-manager="transactionManager">
    				<batch:chunk reader="clienteErrorChunk0203FlatFileItemReader" 
    				             writer="clienteJdbcBatchWriter" 
    				             commit-interval="50"/>
    		        </batch:tasklet>		
    		</batch:step>
    </batch:job>
    1) So why and when I should use the tasklet's transaction-manager attribute?
    2) Am I missing something?
    3) has sense include this attribute for all my Step's tasklets?

    Thanks in advanced

  • #2
    Manuel,

    The step will be transactional by default since Spring Batch internally uses the transaction manager to commit metadata about the running instance (typically the contribution such as the number of items read/processed/written, etc). To do that, it lookups the TransactionManager with name "transactionManager" I believe (or a simple wiring on the PlatformTransactionManager interface).

    If you have more than one transaction manager in your spring config, you'll need to specify the name of the bean you want to use. This is a typical situation where you'll have to add the "transaction-manager" attribute in the tasklet config.

    See also http://static.springsource.org/sprin...rJobRepository

    HTH,
    S.

    Comment


    • #3
      Hi Stéphane

      Thanks for the reply

      The step will be transactional by default since Spring Batch internally uses the transaction manager to commit metadata about the running instance (typically the contribution such as the number of items read/processed/written, etc). To do that, it lookups the TransactionManager with name "transactionManager" I believe (or a simple wiring on the PlatformTransactionManager interface).
      Yes, you are correct, closely related with these two attributes


      Code:
      <batch:job-repository id="jobRepository"
       		              data-source="dataSource"
              	              transaction-manager="transactionManager"
      			      isolation-level-for-create="SERIALIZABLE"
      			      table-prefix="BATCH_"
      		                   />
      If you have more than one transaction manager in your spring config, you'll need to specify the name of the bean you want to use. This is a typical situation where you'll have to add the "transaction-manager" attribute in the tasklet config.
      Yes, but If I have two differents datasources like for example for Mysql and Postgresql and I want do a batch migration I must work with JTA (with Atomikos)

      Thanks

      Comment


      • #4
        Originally posted by dr_pompeii View Post
        Yes, but If I have two differents datasources like for example for Mysql and Postgresql and I want do a batch migration I must work with JTA (with Atomikos)
        That's unrelated. You can have a situation where you have two different PlatformTransactionManager beans in your application context. A simple example is the use of the JmsTransactionManager for non-XA consumption of message (i.e. no transaction timeout for long processing) and a regular, for instance, JtaTransactionManager.

        In such case, Spring Batch needs to know which one it has to take. And that's the situation where you need to provide an explicit id for it.

        HTH,
        S.

        Comment

        Working...
        X