Skip to content

@Transactional test does not execute all JPA lifecycle callback methods #28228

Closed
@hughwphamill

Description

@hughwphamill

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.

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)in: testIssues in the test moduletype: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions