【问题标题】:Get all changes made to children entities with Hibernate Envers使用 Hibernate Envers 获取对子实体所做的所有更改
【发布时间】:2015-05-11 17:06:29
【问题描述】:
@Entity
class Foo {
    List<Bar> bars;
}

如何使用 Hibernate Envers 获得对拥有许多孩子的对象所做的所有更改?我有兴趣了解对条形图所做的所有更改(即创建、修改、删除)

https://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/envers/AuditReader.html

【问题讨论】:

    标签: java hibernate hibernate-envers


    【解决方案1】:

    请创建一个扩展 org.hibernate.envers.event.AuditEventListener 的自定义事件侦听器。然后,您可以覆盖以下任何方法来记录更改:

    1. onPostRecreateCollection
    2. onPreRemoveCollection
    3. 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多