【问题标题】:Reading audited relations with Hibernate Envers阅读与 Hibernate Envers 的审计关系
【发布时间】:2015-01-21 23:55:11
【问题描述】:

我们正在使用 Hibernate Envers (4.3.5.Final) 和 Spring Data Envers (0.2.0.RELEASE)。

使用以下实体设置,当我查询实体 A 的特定版本时,我无法读取 B 上的 C 列表(始终为空):

@Entity
@Audited
class A {
    private Integer id;
    @ManyToMany
    private List<B> bList = new ArrayList<>();
}

@Entity
@Audited
class B {
    private Integer id;
    @ManyToMany
    private List<C> cList = new ArrayList<>();
}

@Entity
@Audited
class C {
    private Integer id;
}

生成以下表格:

A、A_AUD、A_B、A_B_AUD、B_C、B_C_AUD

我的猜测是,这是不可能的,因为审计表缺少从 A 到 C 的关系信息,但我不确定。您能否确认这一点或给我一个提示如何实现这一点?

【问题讨论】:

    标签: hibernate spring-data hibernate-envers


    【解决方案1】:

    我刚刚使用 Hibernate Envers 5.2.7 对此进行了测试,没有任何问题。也许这是一个已修复的旧错误,或者是 Spring Data Envers 实现的问题:

    final EntityA a = auditReader.find( EntityA.class, aId, revision );
    assertNotNull( a );
    assertTrue( !a.getBList().isEmpty() );
    for ( EntityB b : a.getBList() ) {
      assertTrue( !b.getCList().isEmpty() );
      for( EntityC c : b.getCList() ) {
        assertNotNull( c );
        System.out.println( c );
      }
    }
    

    上面打印出我的EntityC 实例就好了。

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 2013-02-08
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      • 2020-11-17
      • 2011-07-10
      • 1970-01-01
      • 2018-04-18
      相关资源
      最近更新 更多