Hibernate envers with postgresql sees byte array as type bytea, but i expect it to be oid

273 Views Asked by At

After upgrading tot spring 3 and hibernate core/envers to 6.* this issue occurs.

  • Spring Boot version 3.1.4
  • Hibernate core and envers version 6.2.5.Final (tried different versions)
  • PostgreSQL jdbc driver version 42.6.0 (tried different versions)

I have an entity with column;

@Lob
private byte[] content;

My database table has a column named content with type oid.

Since i use envers, i also have a _aud table with a column named 'content' with type oid.

While starting up the schema validation gives the following error;

Schema-validation: wrong column type encountered in column [content] in table [xxxxx_aud]; found [oid (Types#BIGINT)], but expecting [bytea (Types#VARBINARY)]

If i add @NotAudited to this field, it works, so my normal table works with type OID. I expect my hibernate envers column also to be OID, but bytea is wanted.

Do i need to convert my _aud table column content to bytea or is this a hibernate envers bug?

2

There are 2 best solutions below

0
NickH On BEST ANSWER

I managed to fix this by creating a custom Converter

  @Converter
  public class ContentConverter implements AttributeConverter<byte[], Blob> {

  //code

  }

and added the annotation to the field;

  @Lob
  @Convert(converter = ContentConverter.class)
  private byte[] content;
3
Mr_Thorynque On

Maybe you can add an annotation

@Lob @JdbcTypeCode(Types.BINARY) private byte[] content;

In other hand, that mapping depend of org.hibernate.dialect.PostgreSQLDialect you use and its version. You can find an answer : Hibernate, Postgresql: Column "x" is of type oid but expression is of type byte