java.lang.ClassCastException: org.hibernate.lob.SerializableBlob

Hibernate JIRA | Ari Miller | 1 decade ago
  1. 0

    I'm entering this at the request of emmanuel, base on forum post http://forum.hibernate.org/viewtopic.php?p=2249076#2249076 org.hibernate.type.ByteArrayBlobType is not compatible with updating or creating Blobs in Oracle, due to a problem with Oracle Blob handling. You can see the error in the stack trace given below. Basically, you receive a class cast exception if you call setBlob on an OraclePreparedStatement with anything besides an oracle.sql.BLOB. I believe this problem can be fixed by borrowing a portion of the Blob handling from org.hibernate.type.BlobType. Specifically, switch to using an input stream to insert the blob if the dialect in use, Oracle in this case, requires it. The following chunk of code from BlobType can be appropriated: public void set(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { if (value==null) { st.setNull(index, Types.BLOB); } else { if (value instanceof SerializableBlob) { value = ( (SerializableBlob) value ).getWrappedBlob(); } final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob() && (value instanceof BlobImpl); if ( useInputStream ) { BlobImpl blob = (BlobImpl) value; st.setBinaryStream( index, blob.getBinaryStream(), (int) blob.length() ); } else { st.setBlob(index, (Blob) value); } } } The current code in ByteArrayBlobType always calls st.setBlob( index, Hibernate.createBlob( toSet ) ); It looks like the ByteArrayBlobType would need access to a SessionImplementor to do this, but I assume that is feasible. I tried using ByteArrayBlobType against Oracle 9i, and 10g, with versions 9 and 10 of the driver, using the oci client and the thick client, and while you end up with a different stack trace, the problem is always present. Here is the stack trace with the 10.1.0.4 driver: java.lang.ClassCastException: org.hibernate.lob.SerializableBlob at oracle.jdbc.driver.OraclePreparedStatement.setBlob(OraclePreparedStatement.java:5909) at org.hibernate.type.ByteArrayBlobType.nullSafeSet(ByteArrayBlobType.java:92) at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:141) at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1617) at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1594) at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1850) at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)

    Hibernate JIRA | 1 decade ago | Ari Miller
    java.lang.ClassCastException: org.hibernate.lob.SerializableBlob
  2. 0

    I'm entering this at the request of emmanuel, base on forum post http://forum.hibernate.org/viewtopic.php?p=2249076#2249076 org.hibernate.type.ByteArrayBlobType is not compatible with updating or creating Blobs in Oracle, due to a problem with Oracle Blob handling. You can see the error in the stack trace given below. Basically, you receive a class cast exception if you call setBlob on an OraclePreparedStatement with anything besides an oracle.sql.BLOB. I believe this problem can be fixed by borrowing a portion of the Blob handling from org.hibernate.type.BlobType. Specifically, switch to using an input stream to insert the blob if the dialect in use, Oracle in this case, requires it. The following chunk of code from BlobType can be appropriated: public void set(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { if (value==null) { st.setNull(index, Types.BLOB); } else { if (value instanceof SerializableBlob) { value = ( (SerializableBlob) value ).getWrappedBlob(); } final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob() && (value instanceof BlobImpl); if ( useInputStream ) { BlobImpl blob = (BlobImpl) value; st.setBinaryStream( index, blob.getBinaryStream(), (int) blob.length() ); } else { st.setBlob(index, (Blob) value); } } } The current code in ByteArrayBlobType always calls st.setBlob( index, Hibernate.createBlob( toSet ) ); It looks like the ByteArrayBlobType would need access to a SessionImplementor to do this, but I assume that is feasible. I tried using ByteArrayBlobType against Oracle 9i, and 10g, with versions 9 and 10 of the driver, using the oci client and the thick client, and while you end up with a different stack trace, the problem is always present. Here is the stack trace with the 10.1.0.4 driver: java.lang.ClassCastException: org.hibernate.lob.SerializableBlob at oracle.jdbc.driver.OraclePreparedStatement.setBlob(OraclePreparedStatement.java:5909) at org.hibernate.type.ByteArrayBlobType.nullSafeSet(ByteArrayBlobType.java:92) at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:141) at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1617) at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1594) at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1850) at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)

    Hibernate JIRA | 1 decade ago | Ari Miller
    java.lang.ClassCastException: org.hibernate.lob.SerializableBlob
  3. 0

    SerialBlob problem

    Oracle Community | 1 decade ago | 470257
    java.lang.ClassCastException: javax.sql.rowset.serial.SerialBlob
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    javax.sql.rowset.serial.SerialBlob incompatible with oracle.sql.BLOB

    Stack Overflow | 2 years ago
    java.lang.ClassCastException: javax.sql.rowset.serial.SerialBlob incompatible with oracle.sql.BLOB
  6. 0

    Overcoming Fear: Spring, Hibernate and Oracle Stored Procedures

    blogspot.com | 4 months ago
    java.lang.ClassCastException: org.hibernate.lob.SerializableBlob incompatible with oracle.sql.BLOB

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ClassCastException

      org.hibernate.lob.SerializableBlob

      at oracle.jdbc.driver.OraclePreparedStatement.setBlob()
    2. Oracle jdbc
      OraclePreparedStatement.setBlob
      1. oracle.jdbc.driver.OraclePreparedStatement.setBlob(OraclePreparedStatement.java:5909)
      1 frame
    3. Hibernate
      BasicEntityPersister.insert
      1. org.hibernate.type.ByteArrayBlobType.nullSafeSet(ByteArrayBlobType.java:92)
      2. org.hibernate.type.CustomType.nullSafeSet(CustomType.java:141)
      3. org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1617)
      4. org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1594)
      5. org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1850)
      6. org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
      6 frames
    4. Hibernate
      EntityInsertAction.execute
      1. org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
      1 frame
    5. Hibernate
      ActionQueue.executeActions
      1. org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
      2. org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
      3. org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
      3 frames
    6. Hibernate
      SessionImpl.managedFlush
      1. org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
      2. org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
      3. org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
      4. org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
      4 frames
    7. Hibernate
      JDBCTransaction.commit
      1. org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
      1 frame