@Audited table and byte[] @Lob field problem

105 Views Asked by At

I have adudited table with @Lob field. Without @Audited saving object by Spring CrudRepository works ok, but when i want audit turn on i get error: PSQLException: ERROR: column "content" is of type oid but expression is of type bytea. How to resolve this ? Content column in PostgreSQL database is oid type (for both tables). On Hibernate 5.x the same configuration works, but not o Hibernate 6.x.

@Entity
@Audited
@Table(name = "up_test")
@Getter @Setter
public class UploadTestEntity extends BaseEntity {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "up_test_seq")
    @TableGenerator(table = "id_generator", name = "up_test_seq", initialValue = 1, allocationSize = 1)    
    private Integer id; 
    
    @Lob
    private byte[] content;
    
}
1

There are 1 best solutions below

0
On

Just remove the @Lob annotation.

The Postgres JDBC driver does not support handling the bytea type via the JDBC LOB APIs setBlob()/getBlob(). I don't know why, and it seems like something that should be supported.

But on the other hand, you don't need it here. The most natural way to handle a field of type byte[] mapping to bytea is to use setBytes()/getBytes(), which is the job of Hibernate's VarbinaryJdbcType.

I don't know where people got the idea that they needed to use @Lob for this instead of just going with the default mapping for byte[].