如何填写审计可扩展实体映射超级 class 中的审计字段?

How to fill audit fields that are in Audit extendable entity mapped super class?

我正在使用 hibernate envers 来审计我的实体。 我有这样的 OfficeEntity:

@Entity
@Audited
@EntityListeners({AuditingEntityListener.class})
@Table(name = "office")
@AuditTable("office_aud")
public class OfficeEntity extends Auditable{

      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "office_id")
      private Long id;

      @Column(name = "office_code")
      private String officeCode;

      @Column(name = "office_name")
      private String OfficeName;

      //getters & setters & constructor 
}

和奥迪table这样的实体:

@MappedSuperclass
public class Auditable{

      @CreatedBy
      @Column(name = "created_by")
      private String createdBy;

      @CreatedDate
      @Column(name = "created_date")
      private Date createdDate;

      @LastModifiedBy
      @Column(name = "last_modified_by")
      private String lastModifiedBy;

      @LastModifiedDate
      @Column(name = "last_modified_date")
      private Date lastModifiedDate;

      //getters & setters & constructor
}

好像用这个结构审计字段没有填写office_audtable。 所以有人知道我如何填写 office_aud table 中的审计字段吗??

我在 hibernate envers 中发现注释解决了这个问题。 所以你可以添加:

@AuditOverride(forClass = Auditable.class)

到子实体 class 并且将设置审计字段。 子实体将是这样的:

@Entity
@Audited
@Table(name = "office")
@AuditOverride(forClass = Auditable.class)
@AuditTable("office_aud")
public class OfficeEntity extends Auditable{

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "office_id")
  private Long id;

  @Column(name = "office_code")
  private String officeCode;

  @Column(name = "office_name")
  private String OfficeName;

  //getters & setters & constructor 

}