Hibernate envers ignores types from hibernate-types-52 library

548 views Asked by At

I'm having an entity which is audited using hibernate envers. Using "jsonb" type from hibernate-types-52 library for one of the fields. Example:

@Entity
@Audited
@Table(name = "entity")
class Entity() {

@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
var field1: Map<String, Any> = emptyMap()

}

And here's the generated SQL:

 create table entity (
    field1 jsonb
 )

create table entity_aud (
    field1 uuid     
 )

As you can see, jsonb type is not being used for field1 in _aud table. Experiencing same behavior when using psql_enum type. This of course makes an exception, when trying to persist an entity. How can I make envers recognize such a types and make it generate schema accordingly?

1

There are 1 answers

0
Vlad Mihalcea On

Most likely, this is because Hibernate maps the JDBC Types.OTHER to PostgresUUIDType.

As I explained in this article, you can create a custom Dialect that extends the PostgreSQLDialect:

public class PostgreSQL10JsonDialect
        extends PostgreSQL10Dialect {
 
    public PostgreSQL10JsonDialect() {
        super();
        this.registerHibernateType(
            Types.OTHER, JsonNodeBinaryType.class.getName()
        );
    }
}

And if we provide the custom PostgreSQL10JsonDialect via the hibernate.dialect configuration property:

<property 
    name="hibernate.dialect"
    value="com.vladmihalcea.book.hpjp.hibernate.type.json.PostgreSQL10JsonDialect"
/>