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

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 03:25:23

问题


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 i.e. 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.


回答1:


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.




回答2:


See,

http://en.wikibooks.org/wiki/Java_Persistence/Auditing_and_Security

http://en.wikibooks.org/wiki/Java_Persistence/Advanced_Topics#History

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Auditing

http://wiki.eclipse.org/EclipseLink/Examples/JPA/History



来源:https://stackoverflow.com/questions/6450689/how-to-use-auditing-in-jpa-spring-data-jpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!