Closed
Description
Spring Boot v2.6.4
@Transactional
tests are useful to roll back any test data created during tests; however, when a Spring integration test is annotated with @Transactional
the following JPA lifecycle callback methods are not executed:
@PostPersist
@PostLoad
@PreUpdate
@PostUpdate
Example project with tests demonstrating the issue here:
https://github.com/hughwphamill/transaction-test-entity-issue
I understand this is the desired behavior from a JPA perspective, but it's still undesirable from a test perspective.
@Transactional
is incredibly useful in Spring integration tests to roll back test data, while exercising your whole application end to end. If your business logic uses JPA entity listeners then your application can't be properly tested in a @Transactional
test.