Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formula mappings are currently not supported - Hibernate ORM Envers

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.

like image 255
Kamil Nękanowicz Avatar asked Jun 02 '17 11:06

Kamil Nękanowicz


1 Answers

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
}
like image 198
Naros Avatar answered Sep 20 '22 12:09

Naros