Hi, i'm using Hibernate 3.1 with SQL Server 2005.
i am in trouble. i create a userType for modify the blobType cause i use 3 database and i have to switch these dbs. the code in the nullSafeSet method for mysql is this:
java.sql.Blob blob = Hibernate.createBlob((InputStream)value);
ps.setBlob(index, blob);
where "value" is my object (a binaryStream).
And this code is ok.
With oracle i inserted the code of Scott Miller for problems with oracle/blog
but also this code is ok.
Now, when i have to use SQL Server i have error in code. This is my code:
try
{
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(byteStream);
os.flush();
os.writeObject(value);
os.flush();
os.close();
//retrieves byte array
byte[] valueByte = byteStream.toByteArray();
SQLServerConnection ssconn = (SQLServerConnection) ps.getConnection();
//SQLServerBlob (SQLServerConnection, byte[])
SQLServerBlob blob = new SQLServerBlob(ssconn, valueByte);
ps.setBlob(index, blob);
}catch(IOException e){}
But doesn't work!
WARN JDBCExceptionReporter - SQL Error: 0, SQLState: null
ERROR AbstractFlushingEventListener - Could not synchronize database state with session
please help me write the nullSafeSet method for write an Object in a column "Image" of my db!
|