Document: http://www.hibernate.org/73.html
Code:
Quote:
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException
{
Blob blob = rs.getBlob(names[0]);
return blob.getBytes(1, (int) blob.length());
}
Having this code I got
StreamCorruptedException when trying to deserialize the object with
ObjectInputStream.
After examining byte arrays before storing into a table (after serialization) and after retrieving from a table (before deserialization) I found that the latter array is short of the first byte!
So the code should be:
Quote:
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException
{
Blob blob = rs.getBlob(names[0]);
return blob.getBytes(0, (int) blob.length());
}
With this code everything works fine.
However Java API on Blob says:
Quote:
Code:
public byte[] getBytes(long pos,
int length)
throws SQLExceptionRetrieves all or part of the BLOB value that this Blob object represents, as an array of bytes. This byte array contains up to length consecutive bytes starting at position pos.
Parameters:
pos - the ordinal position of the first byte in the BLOB value to be extracted;
the first byte is at position 1length - the number of consecutive bytes to be copied
It looks like the Java API in that part is wrong!
Can somebody explain this?