Skip to content

@Transactional not working when using two contexts and @Configurable weaved with AspectJ #11461

Closed

Description

@cdalexndr

Spring Boot 1.5.9.RELEASE

Provided test case where inside a @Transactional method, the previously persisted entity is not present in entity manager, eg:

    @Transactional
    public void doWork() {
        TestTable entity = testTableRepository.save( new TestTable( "test" ) );
        Assert.assertTrue( entityManager.contains( entity ) );
    }

From my investigation, issue is related to transaction managers mixing from the two contexts because of AnnotationTransactionAspect caching of a transaction manager from previous context.
Thus, the @Transactional method uses the previous context transaction manager (weaved aspect), and the repository save method will use the current context transaction manager creating a new temporary transaction that closes immediately after entity is persisted.

Sample: https://github.com/cdalexndr/spring-boot-issue-11461

Activity

  1. added
    status: waiting-for-triage
    on Jan 1, 2018
  2. snicoll commented on Jan 2, 2018

    @snicoll
    Member

    See also #11123

  3. wilkinsona commented on Apr 26, 2018

    @wilkinsona
    Member

    This is the same as, or at least very similar to, https://jira.spring.io/browse/SPR-16227. I'm going to close this issue in favour of that Spring Framework issue. I've just commented on it providing a sample that illustrates a case of an aspect using a stale bean factory.

  4. added
    status: invalid
    for: external-project
    and removed
    status: waiting-for-triage
    on Apr 26, 2018
  5. cdalexndr commented on Aug 18, 2020

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectstatus: invalid

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions