Spring Data JPA and Spring Boot auditing with Hibernate Envers

蹲街弑〆低调 提交于 2019-12-19 10:27:18

问题


I am using Spring Data JPA and Spring Boot for my project.

I have Audit requirement for Objects(Create/Update/Delete). I may need to get Audit revisions for particular objects too. I have checked on net that Spring Data Envers cant get revisions and doesn't track deletions?

So my Question is :

1) Can we integrate Hibernate Envers with Spring data JPA?

2) We have native queries, HQLs and Spring data JPA update/save/delete dynamic queries, so would Hibernate envers be able to track object for all?

As I am new to Auditing , please let me know about above questions.

Thank you.


回答1:


Can we integrate Hibernate envers with Spring data JPA?

Yes, Hibernate Envers specifically integrates directly with Hibernate ORM and since Spring Data JPA already integrates with Hibernate ORM, you get this out-of-the-box.

We have native queries, HQLs and Spring data JPA update/save/delete dynamic queries, so would Hibernate envers be able to track object for all?

As long as you're manipulating entities through the Session save/update or the EntityManager's persist/merge operations, Hibernate will raise the necessary events for Envers to track your changes.

If you are using Native SQL or JPA's CriteriaUpdate/CriteriaDelete operations to manipulate database records, then no Envers will not pickup those changes. That is because Hibernate will not raise an event for those bulk or stateless operations allowing Envers to audit those changes.




回答2:


it is possible and it is easy! I did an example project using these technologies: Spring boot, Spring data jpa and hibernate with Envers to audit some tables with relationships.

Here is the example: https://github.com/juanca87/example-envers

I hope it will be useful to you, if you have any questions, please let me know.




回答3:


Yes, there is no problem with Spring Data JPA and Hibernate Envers integration. It tracks save, update and delete operations. You only have to add @Audited annotation above your class.



来源:https://stackoverflow.com/questions/42340179/spring-data-jpa-and-spring-boot-auditing-with-hibernate-envers

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