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?
Most likely, this is because Hibernate maps the JDBC
Types.OTHER
toPostgresUUIDType
.As I explained in this article, you can create a custom
Dialect
that extends thePostgreSQLDialect
:And if we provide the custom
PostgreSQL10JsonDialect
via thehibernate.dialect
configuration property: