Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation of existing transactions with transaction synchronization turned off not working (?) [SPR-15016] #19583

Closed
spring-projects-issues opened this issue Dec 14, 2016 · 1 comment
Assignees

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Dec 14, 2016

Vojtech Toman opened SPR-15016 and commented

In out project, we have our own transaction manager implementation. In the test suite, we have a test that checks the various cases in transaction propagation, including the following (requesting a RW transaction while the current transaction is RO):

class A {
  @Autowired
  private B b;

  @Transactional(readOnly = true)
  public void readOnly() {
    b.readWrite();
  }
}

class B {
  @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
  public void readWrite() {
    ...
  }
}

As expected, the call to b.readWrite() fails with an IllegalTransactionStateException. However, when I disable transaction synchronization in our transaction manager, I don't get an exception any more. In the code of AbstractPlatformTransactionManager.handleExistingtransaction(), I see that the check for this case uses TransactionSynchronizationManager.isCurrentTransactionReadOnly() which, obviously, returns false if transaction synchronization is turned off. I believe this is a bug. (It's possible that this follows from the semantics of transaction synchronization in which case I would be grateful if somebody could explain me the reasoning behind this).


Affects: 4.3.4

Issue Links:

  • #17201 Log warning for Isolation.READ_UNCOMMITTED with Propagation.NOT_SUPPORTED
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 14, 2016

Juergen Hoeller commented

I'm afraid this is by design: Without synchronization active, outer vs inner transaction scopes only communicate via the resources involved, not seeing each other's transaction definition metadata. Validating Spring transaction definitions across demarcation levels is indeed a feature that only comes in through the transaction synchronization arrangement. Also, we're only really using it for validation purposes around transaction hints here: The transaction read-only flag was never meant to be a hard constraint but rather just a soft hint for runtime optimizations in a read-only scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.