Hibernate:Envers 不适用于没有成员字段的派生类

问题描述 投票:0回答:1

给定以下基类...

...
import org.hibernate.envers.Audited;

@Audited
@Entity
@Table(
    name = "account",
    indexes = {
      @Index(name = "account_currency_id_idx", columnList = "currency_id")
    })
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "account_type")
public class Account {

  @Id
  @GeneratedValue
  @Setter(AccessLevel.NONE)
  @NotNull
  private Long id;

  @Audited
  @LastModifiedDate
  @Column(name = "last_modified_date_time")
  @Setter(AccessLevel.NONE)
  private LocalDateTime lastModifiedDateTime;

  @Audited
  @LastModifiedBy
  @Setter(AccessLevel.NONE)
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "last_modified_by_user_id", referencedColumnName = "id")
  @Audited(targetAuditMode = NOT_AUDITED)
  private User lastModifiedByUser;

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "currency_id", referencedColumnName = "id")
  @ApiFieldMappingProperty("currencyId")
  @Audited(targetAuditMode = NOT_AUDITED)
  private Currency currency;

  @NotNull
  @Column(name = "open_date", nullable = false)
  private LocalDate openDate;

  @Column(name = "close_date")
  private LocalDate closeDate;

  ...
}

...我定义了两个没有成员字段的派生类,但带有一个鉴别器值,可以让我自动区分帐户类型。这是第一个派生类...

...
@Entity(name = "domestic_account")
@DiscriminatorValue("DOMESTIC")
public DomesticAccount extends Account {
}

...这是第二个:

@Entity(name = "offshore_account")
@DiscriminatorValue("OFFSHORE")
public OffshoreAccount extends Account {
}

在代码中我从不直接使用类

Account
;相反,我总是实例化(并保存)一个
DomesticAccount
OffshoreAccount

问题是,即使我使用

@Audited
启用审核,更改也不会被记录,并且表
ACCOUNT_AUD
仍为空。

我错过了什么吗?非常感谢任何帮助。

java spring hibernate hibernate-envers
1个回答
0
投票

最后,用

@Audited
注解派生类解决了这个问题:

...
import org.hibernate.envers.Audited;

@Audited
@Entity(name = "domestic_account")
@DiscriminatorValue("DOMESTIC")
public DomesticAccount extends Account {
}

也非常感谢Christian Beikov的支持。

© www.soinside.com 2019 - 2024. All rights reserved.