使用 Hibernate Envers 获取对 children 个实体所做的所有更改
Get all changes made to children entities with Hibernate Envers
@Entity
class Foo {
List<Bar> bars;
}
如何使用 Hibernate Envers 获得对我的 object 进行的所有更改,其中有很多 children?我有兴趣了解对栏所做的所有更改(即创建、修改、删除)
https://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/envers/AuditReader.html
请创建一个扩展 org.hibernate.envers.event.AuditEventListener
的自定义事件侦听器。然后您可以覆盖以下任何方法来记录更改:
onPostRecreateCollection
onPreRemoveCollection
onPreUpdateCollection
您可以在 EntityManager 配置中注册您的自定义侦听器。下面是一个简单的例子:
<prop key="hibernate.ejb.event.pre-collection-update">
com.bla.bla.audit.listener.AuditEventListener
</prop>
<prop key="hibernate.ejb.event.pre-collection-remove">
com.bla.bla.audit.listener.AuditEventListener
</prop>
<prop key="hibernate.ejb.event.post-collection-recreate">
com.bla.bla.audit.listener.AuditEventListener
</prop>
@Entity
class Foo {
List<Bar> bars;
}
如何使用 Hibernate Envers 获得对我的 object 进行的所有更改,其中有很多 children?我有兴趣了解对栏所做的所有更改(即创建、修改、删除)
https://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/envers/AuditReader.html
请创建一个扩展 org.hibernate.envers.event.AuditEventListener
的自定义事件侦听器。然后您可以覆盖以下任何方法来记录更改:
onPostRecreateCollection
onPreRemoveCollection
onPreUpdateCollection
您可以在 EntityManager 配置中注册您的自定义侦听器。下面是一个简单的例子:
<prop key="hibernate.ejb.event.pre-collection-update">
com.bla.bla.audit.listener.AuditEventListener
</prop>
<prop key="hibernate.ejb.event.pre-collection-remove">
com.bla.bla.audit.listener.AuditEventListener
</prop>
<prop key="hibernate.ejb.event.post-collection-recreate">
com.bla.bla.audit.listener.AuditEventListener
</prop>