How can I run actions in my mapped JPA classes whenever they are stored in the database?

I want to have a function in one of my annotated JPA classes that is called every time the EntityManager stores them in a database (like an event listener). Is it possible? Preferably, I would like to distinguish whether it will just be saved or has just been saved.

To accomplish what I want, this time I probably could work with the setter method, but that would be completely wrong.

+5
source share
2 answers

Of course, check out these examples . You have:

  • @PrePersist;
  • @PreUpdate;
  • @PreRemove.
  • @PostPersist;
  • @PostUpdate; and
  • @PostRemove.

( Hanno). , .

+7

All Articles