Results 1 to 4 of 4

Thread: When use the tasklet's transaction-manager attribute?

  1. #1
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Question 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
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  2. #2

    Default

    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.

  3. #3
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  4. #4

    Default

    Quote 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •