Featured post
Hibernate, Postgresql: Column "x" is of type oid but expression is of type byte -
i have strange problem regarding hibernate mapping containing large objects (blob), when switching between different databases.
@lob private byte[] binarydata;
the field above creates byte array field in mysql , in oracle, in postresql creates field of type oid.
now when try access field works fine in other databases, in postgresql fails following error
column "binarydata" of type oid expression of type bytea.
so tried remove "@lob" annotation, solve problem postgresql, in mysql without annotation, hibernate creates field of type "tinyblob", small in of our cases. and, want use project in more 1 environment annoying have 2 different mappings switch.
is there annotation forces postgresql use bytea instead of oid fields annotated @lob? or somehow possible omit @lob , put else in order force mysql allocate larger datatype using @lob?
i imagine have solution this
if (field of type oid) store oid else if (field of type bytea) store bytea else // not storable
and same getter, if there exists way kind of this
edit:
the following declaration working. allocates column oid, hibernate using knows how store , retrieve data such field
@lob @type(type="org.hibernate.type.primitivebytearrayblobtype") private byte[] binaryfile;
this field mapping defined in org.hibernate.dialect.postgresqldialect
, can changed subclassing , configuring app use modified dialect when running postgres.
the relevant incantation in subclass put
registercolumntype( types.blob, "bytea" );
in constructor after call super()
.
- Get link
- X
- Other Apps
Comments
Post a Comment