Formula mappings are currently not supported - Hibernate ORM Envers

Kamil Nekanowicz :

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.

Naros :

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
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=435889&siteId=1