On Postgres @Lob is breaking for byte[] as it tries to save it as oid, and for String also same problem occurs. Below code is breaking on postgres which is working fine on oracle.
@Lob
private String stringField;
and
@Lob
private byte[] someByteStream;
In order to fix above on postgres have written below custom hibernate.dialect
public class PostgreSQLDialectCustom extends PostgreSQL82Dialect{
public PostgreSQLDialectCustom()
{
super();
registerColumnType(Types.BLOB, "bytea");
}
@Override
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
if (Types.CLOB == sqlTypeDescriptor.getSqlType()) {
return LongVarcharTypeDescriptor.INSTANCE;
}
return super.remapSqlTypeDescriptor(sqlTypeDescriptor);
}
}
Now configure custom dialect in hibernate
hibernate.dialect=X.Y.Z.PostgreSQLDialectCustom
X.Y.Z is package name.
Now it working fine. NOTE- My Hibernate version - 5.2.8.Final Postgres version- 9.6.3