I'm getting the following error while inserting a blob column into the Oracle 8.1.7 table:
java.lang.ClassCastException: net.sf.hibernate.lob.BlobImpl
I'm doing this persistence using the custom UserType implementation. Here is the code for that:
package org.jbpm.util.db;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.sql.Blob;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.UserType;
public class BinaryBlobType implements UserType
{
// System.arraycopy(emptyStr.getBytes(), 0, emptyByte, 0,emptyStr.getBytes().length);
public int[] sqlTypes()
{
return new int[] { Types.BLOB };
}
public Class returnedClass()
{
return byte[].class;
}
public boolean equals(Object x, Object y)
{
return (x == y)
|| (x != null
&& y != null
&& java.util.Arrays.equals((byte[]) x, (byte[]) y));
}
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());
}
public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException
{
// st.setBytes(index, (byte[]) value);
byte[] empByte;
String emptyString = new String("Empty");
empByte = emptyString.getBytes();
if ((byte[]) value != null){
st.setBlob(index,Hibernate.createBlob((byte[]) value));
}
else
{
System.out.println("Blob Empty :" + index);
st.setBlob(index,(java.sql.Blob)Hibernate.createBlob(empByte));
}
}
public Object deepCopy(Object value)
{
if (value == null) return null;
byte[] bytes = (byte[]) value;
byte[] result = new byte[bytes.length];
System.arraycopy(bytes, 0, result, 0, bytes.length);
return result;
}
public boolean isMutable()
{
return true;
}
}
You could see that I'm printing "Blob Empty". That's why I was trying to persist with some junk data still with the same problem. Any help is greately appreciated.
Thanks
|