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
Comment From: snicoll
See also #11123
Comment From: wilkinsona
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.
Comment From: cdalexndr
Main issue: https://github.com/spring-projects/spring-framework/issues/11019