How to use auditing in JPA / Spring - JPA date?

I am using JPA and Spring -Data JPA in the project. I have one table wherei Insert, and then update the data. However, I need audit information to save the state of all objects, that is, I need information about the state of the insert and all subsequent updates in another table. I know that I can use triggers in the database for this. However, can this be done using JPA / Spring Data JPA?

Any help would be appreciated.

+6
source share
2 answers

The JPA specification ( section 3.5 ) defines lifecycle callback methods:

  • prePersist
  • postPersist
  • preRemove
  • postRemove
  • preUpdate
  • postUpdate
  • afterload

which are probably the closest things you will find in pure JPA. SpringData itself has additional audit capabilities, which are at a slightly higher level of abstraction. He describes them in section 2.4 of the reference guide.

+6
source

Source: https://habr.com/ru/post/891186/


All Articles