Skip to content

lost transactionAttribute when using chaining StepBuilderΒ #3686

Closed

Description

@hoyeol

lost transactionAttribute when using chaining StepBuilder.

  • according to below code, there will be lost "transactionAttribute" already set.
DefaultTransactionAttribute readOnlyTxAttribute = new DefaultTransactionAttribute();
readOnlyTxAttribute.setReadOnly(true);
stepBuilderFactory.get("stepName")
.transactionManager(txManager)
.<InputType, OutputType>chunk(CHUNK_SIZE)
.reader(reader)
.writer(writer)
.transactionAttribute(readOnlyTxAttribute)
.faultTolerant()
.backOffPolicy(backOffPolicy())
.retryLimit(3)
.retry(SomeException.class)
.build();
  • next below code, does not lost transactionAttribute. (just only difference is "where is transactionAttribute method call")
DefaultTransactionAttribute readOnlyTxAttribute = new DefaultTransactionAttribute();
readOnlyTxAttribute.setReadOnly(true);
stepBuilderFactory.get("stepName")
.transactionManager(txManager)
.<InputType, OutputType>chunk(CHUNK_SIZE)
.reader(reader)
.writer(writer)
.faultTolerant()
.backOffPolicy(backOffPolicy())
.retryLimit(3)
.retry(SomeException.class)
.transactionAttribute(readOnlyTxAttribute)
.build();

it seems to broken compatibility between SimpleStepBuilder and FaultTolerantStepBuilder (and both classes extends AbstractTaskletStepBuilder what have transactionAttribute property.)

there transactionAttributes will be missing on method calls. (there methods does not support copying "transactionAttribute")

  • org.springframework.batch.core.step.builder.SimpleStepBuilder.faultTolerant
  • org.springframework.batch.core.step.builder.FaultTolerantStepBuilder constructor
  • org.springframework.batch.core.step.builder.SimpleStepBuilder constructor
  • org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder constructor
  • org.springframework.batch.core.step.builder.StepBuilderHelper constructor

Activity

  1. acktsap commented on Sep 29, 2021

    @acktsap
    Contributor

    I can't reproduce it by a syntax error.

    Screen Shot 2021-09-30 at 4 47 06

    It looks because the transactionAttribute returns AbstractTaskletStepBuilder, not SimpleStepBuilder.

    public AbstractTaskletStepBuilder<B> transactionAttribute(TransactionAttribute transactionAttribute) {
    this.transactionAttribute = transactionAttribute;
    return this;
    }

    It works when transactionAttribute is after the faultTolerant.

    Screen Shot 2021-09-30 at 4 48 33

  2. acktsap commented on Sep 30, 2021

    @acktsap
    Contributor

    But if #3989 is merged, it should be fixed.

  3. added this to the 5.0.0-M4 milestone on Jul 19, 2022
  4. fmbenhassine commented on Jul 19, 2022

    @fmbenhassine
    Contributor

    Resolved with #3989 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions