Here goes what O'reilly Enterprise JavaBeans, 3.0 says
JDBC has special types for these very large objects. The java.sql.Blob type represents binary data, and java.sql.Clob represents character data.
Here goes PostgreSQLDialect source code
public PostgreSQLDialect() {
super();
...
registerColumnType(Types.VARBINARY, "bytea");
/**
* Notice it maps java.sql.Types.BLOB as oid
*/
registerColumnType(Types.BLOB, "oid");
}
So what you can do
Override PostgreSQLDialect as follows
public class CustomPostgreSQLDialect extends PostgreSQLDialect {
public CustomPostgreSQLDialect() {
super();
registerColumnType(Types.BLOB, "bytea");
}
}
Now just define your custom dialect
<property name="hibernate.dialect" value="br.com.ar.dialect.CustomPostgreSQLDialect"/>
And use your portable JPA @Lob annotation
@Lob
public byte[] getValueBuffer() {
UPDATE
Here has been extracted here
I have an application running in hibernate 3.3.2 and the applications works fine, with all blob fields using oid (byte[] in java)
...
Migrating to hibernate 3.5 all blob fields not work anymore, and the server log shows: ERROR org.hibernate.util.JDBCExceptionReporter - ERROR: column is of type oid but expression is of type bytea
which can be explained here
This generaly is not bug in PG JDBC, but change of default implementation of Hibernate in 3.5 version. In my situation setting compatible property on connection did not helped.
...
Much more this what I saw in 3.5 - beta 2, and i do not know if this was fixed is Hibernate - without @Type annotation - will auto-create column of type oid, but will try to read this as bytea
Interesting is because when he maps Types.BOLB as bytea (See CustomPostgreSQLDialect) He get
Could not execute JDBC batch update
when inserting or updating