当前不支持公式映射 - Hibernate ORM Envers

Formula mappings are currently not supported - Hibernate ORM Envers

我使用 Hibernate Envers:

@Entity 
@Table(name = "user")
@Audited
class User()
{
    private String id;
    @Formula("(SELECT name FROM other c where c.id = id)")
    private Integer name;
}

它抛出:

[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.envers.configuration.internal.metadata.FormulaNotSupportedException: Formula mappings (aside from @DiscriminatorValue) are currently not supported

如何使用@Formula和Hibernate Envers计算实体属性?

仅供参考,当我删除 Hibernate Envers 时它工作正常。

问题是您要求 Envers 审核 @Formula 带注释的列,目前不支持该列。我打开 JIRA HHH-11785 的唯一目的是进一步研究。

但是,您应该能够使用 @NotAudited 注释公式字段,并且 Envers 应该可以很好地与该配置集成。真正的问题是当它发现要跟踪基于公式的字段的历史记录时失败了。

举个例子:

@Entity
@Audited
class User {
  @Formula("SELECT name FROM Other ...")
  @NotAudited
  private String name;
  // other attributes
}