How to make BLOB work on Oracle and PostgreSQL?

Viewed 1077

I have entity with a BLOB column:

@Lob
@Column(name = "SRC")
private byte[] src;

My application works with two databases, Oracle and PostgreSQL. When I start the application with Oracle as written above, all works fine, but when I start with PostgreSQL, I get an error:

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [src] in table [catalogs]; found [bytea (Types#BINARY)], but expecting [oid (Types#BLOB)]

After that I read articles and advice in Google and fix it:

@Lob
@Type(type="org.hibernate.type.BinaryType")
@Column(name = "SRC")
private byte[] src;

Now it works fine with PostgreSQL, but with Oracle I get exception:

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [src] in table [catalogs]; found [blob (Types#BLOB)], but expecting [raw(255) (Types#VARBINARY)]

What should I do to make it work on both databases?

P.S. I have similar problems with CLOB

2 Answers

Unfortunately hibernate entities are db-provider specific.

your sql type should be : bytea (Postgres database)

Related