I have a problem with hibernate and MySQL and inserting a blob.
In our previous version of hibernate (3.6.0) a blob was inserted into the database with BlobTypeDescriptor.STREAM_BINDING. Now the blob is persisted with BlobTypeDescriptor.PRIMITIVE_ARRAY_BINDING. (see org.hibernate.type.descriptor.sql.BlobTypeDescriptor.DEFAULT and the doBind method)
The latter uses twice (2x\!) the number of bytes (I think a byte is encoded as hex) as the streaming option. In our junittest we now get the exception "com.mysql.cj.jdbc.exceptions.PacketTooBigException"
I noticed that the problem doesn't exist for Clob. A provision solution for Clob is made in org.hibernate.dialect.Dialect. I think the same provision solution should be made for Blob.
In Dialect.java the following code is in method Dialect.getSqlTypeDescriptorOverride(int sqlCode):
{code:java}protected SqlTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) { SqlTypeDescriptor descriptor; switch ( sqlCode ) { case Types.CLOB: { descriptor = useInputStreamToInsertBlob() ? ClobTypeDescriptor.STREAM_BINDING : null; break; } default: { descriptor = null; break; } } return descriptor; }{code}
The method could be changed to:
{code:java}protected SqlTypeDescriptor getSqlTypeDescriptorOverride(int sqlCode) { SqlTypeDescriptor descriptor; switch ( sqlCode ) { case Types.CLOB: { descriptor = useInputStreamToInsertBlob() ? ClobTypeDescriptor.STREAM_BINDING : null; break; } case Types.BLOB: { descriptor = useInputStreamToInsertBlob() ? BlobTypeDescriptor.STREAM_BINDING : null; break; } default: { descriptor = null; break; } } return descriptor; }{code}
|
|