简体   繁体   中英

How to use Auditing in JPA/Spring-Data JPA?

I am using JPA & Spring-Data JPA in a project. I have one table wherei Insert and then update the data. However i need the auditing information to save the state of all the objects ie I need state information of insert and all subsequent updates in another Table. I know I can use triggers in database to do this. However, Can this be done using JPA/Spring Data JPA?

Any help would be appreciated.

JPA spec ( section 3.5 ) defines lifecycle callback methods:

  • prePersist
  • postPersist
  • preRemove
  • postRemove
  • preUpdate
  • postUpdate
  • postLoad

which are probably the closest thing you will find in pure JPA. SpringData itself has further auditing capabilities which are at a slightly higher level of abstraction. It describes these in section 2.4 of the reference manual .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM