I use 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;
}
it throws:
[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
How to calculate entity attributes with @Formula and Hibernate Envers?
FYI When I remove Hibernate Envers it works properly.
The problem is that you're asking Envers to audit a @Formula annotated column, which presently isn't supported.  I have opened JIRA HHH-11785 for the sole purpose of looking into this farther.
However, you should be able to annotate the formula field with @NotAudited and Envers should integrate just fine with that configuration.  The real issue is that it fails when it finds the formula-based field's history is to be tracked.
As an example:
@Entity
@Audited
class User {
  @Formula("SELECT name FROM Other ...")
  @NotAudited
  private String name;
  // other attributes
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With