Hibernate envers does not recognize PostgreSQLInetType type from hibernate-types-52

1.4k Views Asked by At

Hibernate envers not able to recognize custom types created using @TypeDef annotations from hibernate-types library.

I have an entity, that uses custom type PostgreSQLInetType.class:

@Entity
@Table(name = "my_acl")
@TypeDef(typeClass = PostgreSQLInetType.class, defaultForType = Inet.class)
@Audited
public class MyAcl {

  Inet acl;

//other fields, getters\setters etc.



}

But during my SpringBoot application start, I'm getting the following exception:

Caused by: org.hibernate.MappingException: Type not supported for auditing: com.vladmihalcea.hibernate.type.basic.PostgreSQLInetType, on entity org.acme.MyAcl, property 'acl'.

Is there any way to fix this or tell Envers how to map PostgreSQLInetType?

3

There are 3 best solutions below

2
On BEST ANSWER

To be usable by Envers, the type would have to implement the org.hibernate.type.BasicType interface.

0
On

I created a PR into hibernate-types project to fix this issue: https://github.com/vladmihalcea/hibernate-types/pull/464.

The PR is merged, and you can see that ImmutableType now implements BasicType.

Please upgrade to hibernate-types version 2.17.3 or newer for this fix to work.

0
On

To use Audited annotation with custom hibernate type use
@Type(type = "com.example.StringBufferStringType") crate two files to configure the custom type and make sure do not return any specific string like "name" cause while creation of table the entity table might get created but while creation of Audit table it will throw an error like unable to determine the specificed column data type.

To resolve above issue return null

 public String getName() {
    return null;
}

go through given link to get more insight on it.

https://docs.jboss.org/hibernate/orm/5.3/userguide/html_single/Hibernate_User_Guide.html#basic-lob