-->
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.  [ 4 posts ] 
Author Message
 Post subject: ByteArrayBlobType incompatible with Oracle
PostPosted: Thu Jun 30, 2005 2:18 pm 
Newbie

Joined: Tue Jun 14, 2005 3:21 pm
Posts: 9
Hibernate version: 3.0.5. Annotations 3.0beta2

Full stack trace of any exception that occurs:
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)


Name and version of the database you are using: Oracle 10.1.0.3 with the 10.1.0.4 ojdbc driver. We are using the thin driver, oracle.jdbc.OracleDriver with a URL that starts jdbc:oracle:thin:@ .

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 above. Basically, you receive a class cast exception if you call setBlob on an OraclePreparedStatement with anything besides an OracleBlob.

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:

Code:
   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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 01, 2005 9:46 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you post your detailed case to JIRA, I need to fixed that at some point.
Oh and since you are an Oracle client, open a case, it's a pity they do not have a quality JDBC driver.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: JIRA bug created for this issue
PostPosted: Fri Jul 01, 2005 11:29 am 
Newbie

Joined: Tue Jun 14, 2005 3:21 pm
Posts: 9
http://opensource.atlassian.com/project ... wse/EJB-24

Please let me know if you need additional information.


Top
 Profile  
 
 Post subject: Workaround until this issue is fixed
PostPosted: Fri Jul 01, 2005 11:38 am 
Newbie

Joined: Tue Jun 14, 2005 3:21 pm
Posts: 9
For anyone who finds this post, the workaround we are using is basically the one described by Hanson Char:
http://hansonchar.blogspot.com/2005/06/ ... te-in.html

It is slightly modified for annotations, so it looks like:
Code:
    @Transient
    public byte[] getImageData() {
        return imageData;
    }

    public void setImageData(byte[] imageData) {
        this.imageData = imageData;
    }

    @Lob
    @Column(name="image_data")
    @SuppressWarnings("unused")
    private Blob getImageBlob() {
     return Hibernate.createBlob(this.imageData);
    }
   
    @SuppressWarnings("unused")
    private void setImageBlob(Blob imageBlob) {
     this.imageData = PersistenceUtils.toByteArray(imageBlob);
    }

PersistenceUtils.toByteArray uses the code provided in Hanson Char's blog entry. in the toByteArray method.


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.