-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: java.lang.ClassCastException in blob persistence
PostPosted: Wed Sep 17, 2003 4:08 pm 
Beginner
Beginner

Joined: Wed Sep 17, 2003 4:07 pm
Posts: 22
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.