【问题标题】:JPA Hibernate and AuditJoinTableJPA Hibernate 和 AuditJoinTable
【发布时间】:2013-12-14 16:42:48
【问题描述】:

我无法创建审计表。我有两个集合一对多的关系。一次是相反的,另一个不是。 auditjointable 注释适用于非反向关系,但不适用于反向关系。

我的代码

@Entity
@Audited
@AuditTable(value = "DDD")
public class Department {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Audited
    private int id;
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    private String name;

    @OneToMany(targetEntity = Professor.class,cascade = CascadeType.ALL)
    @JoinColumn(name = "dept_id")
    @AuditJoinTable(name = "abc")
    private java.util.Collection<Professor> employees;

    @OneToMany(targetEntity = Address.class, mappedBy = "department")<==inverse relation
    @AuditJoinTable(name = "def")
//I tried commenting this out and let the inverse side AuditJoinTable annotation, no luck 
    private java.util.Collection<Address> addresses;
//Getters and setters remove to reduce clutter
}

地址

    @Entity
    @Audited
    public class Address {
        @Id
        @GeneratedValue(strategy= GenerationType.IDENTITY)
        private int id;
        @Column
        private String name;

        @ManyToOne(cascade = CascadeType.ALL)
        @AuditJoinTable(name = "def")
        private Department department;

教授

@Entity
@Audited
public class Professor {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private int id;
    @Column
    private String name;
    private long salary;

    @ManyToOne
    @JoinColumn(name = "dept_id")
    private Department department;

}

当我使用 hibernate.hbm2ddl.auto 创建 scema 时,不会生成“def”autdit 表。但是会生成“abc”审计联合,当员工集合更新时,审计条目会被记录。

我正在使用 休眠/休眠环境 - 3.6.9.Final JPA 1.0

任何指针表示赞赏

【问题讨论】:

    标签: java hibernate jpa audit


    【解决方案1】:

    好吧,经过大量挖掘仍然没有找到让它工作的方法。但是,地址实体的审计表将有一个列来跟踪部门的外键。我启用了

    "hibernate.ejb.event.post-update"

    然后将跟踪集合的任何删除和更新,并更新地址审计表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-24
      • 2013-02-06
      • 2019-10-04
      • 2019-07-20
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多