Results 1 to 8 of 8

Thread: Problem with overriding transaction settings

  1. #1
    Join Date
    Feb 2009
    Location
    Paris
    Posts
    30

    Default Problem with overriding transaction settings

    Hi all,

    I've got a problem with setting my transaction settings in SpringBatch
    For special components, I want to specify a different transaction (actually, no transaction at all).

    I've writen this :
    Code:
    <aop:config>
       <aop:pointcut id="transactional" expression="execution(* mypackage.batch.*.*(..))" />
       <aop:advisor pointcut-ref="transactional" advice-ref="txAdvice" order="0"/>
    </aop:config>
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
       <tx:attributes>
          <tx:method name="*" propagation="NEVER"/>
       </tx:attributes>
    </tx:advice>
    And what I see in my log is
    Code:
    Adding transactional method[*] with attribute [PROPAGATION_NEVER,ISOLATION_DEFAULT]
    So I guess it take in account my configuration

    But, I still see this
    Code:
    Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT

    I'm new in Spring Batch and in transaction too. So, maybe I'm doing something wrong.
    Could you help please ? Thanks.

  2. #2
    Join Date
    Feb 2009
    Location
    Paris
    Posts
    30

    Default

    I'm using WebLogicJtaTransactionManager as a transactionManger, maybe this has something to do with it ?

  3. #3
    Join Date
    Feb 2008
    Posts
    488

    Default

    You can specify the transaction manager and the transaction attributes on the <tasklet/> element of a <step/>.
    Code:
      <step id="step1">
          <tasklet transaction-manager="myTxMgr">
              <chunk reader="itemReader" writer="itemWriter" commit-interval="2"/>
              <transaction-attributes isolation="DEFAULT" propagation="REQUIRED" timeout="30"/>
          </tasklet>
      </step>

  4. #4
    Join Date
    Feb 2009
    Location
    Paris
    Posts
    30

    Default

    Yes, I agree. But, actually I'd like to specify different kind of transaction for itemReader, itemProcessor and itemWriter.
    For example, "PROPAGATION_REQUIRED" for code in read() and write()
    and "PROPAGATION_NEVER" for code in readError(), afterRead(). For logging in databe for instance.
    I guess there is a way to do this ?

  5. #5
    Join Date
    Feb 2009
    Location
    Paris
    Posts
    30

    Default

    Actually, I'm trying to do what is explained in section 11.1 of the Spring Batch Documentation.
    But it does not work. My aopconfig is not taken in account.

    Please, help !

  6. #6
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    I think by default listeners are in requires new propagation, but I'd have to double check. (It might only be the skip listeners) You should be able to use @Transactional though. Your AOP issues may be pointcut related, its tough to say without seeing the actual config.

  7. #7
    Join Date
    Feb 2009
    Location
    Paris
    Posts
    30

    Default

    Hi, I've tried to add the @Transactionnal tag to my method and....it seems to work ! Great !
    I don't understand why it works better than the aop config I've tried but, anyway, it works. That's all I want.
    Thanks a lot for your help !

  8. #8
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    Usually when that happens it's because the pointcut expression is slightly off. It's kind of like a regular expression in that way. (AJDT can help make sure it's actually applying it where you think it is)

Posting Permissions

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