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

guykilcj  于 2022-11-10  发布在  Spring
关注(0)|答案(3)|浏览(126)

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?

vxbzzdmp

vxbzzdmp1#

我在hibernate-types项目中创建了一个PR来解决此问题:https://github.com/vladmihalcea/hibernate-types/pull/464
PR被合并,您可以看到ImmutableType现在实现了BasicType
请升级到hibernate-types版本2.17.3或更高版本以使此修复程序正常工作。

aiqt4smr

aiqt4smr2#

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

pzfprimi

pzfprimi3#

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

相关问题