-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem inserting BLOB with oracle 10g
PostPosted: Tue Aug 16, 2005 3:54 pm 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
Hi All,

After reading various posts related to BLOB issues and following the recommendations from the link http://hansonchar.blogspot.com/2005/06/ ... te-in.html, i got the following exception (see below). Could someone please let me know what's wrong with this? I read almost all the posts related to BLOB issues. Any help on this is greatly appreciated.

I'm using Hibernate 3.1 beta 3, Oracle 10g (10.1.0.2 driver).

I've Notes class as below which has a blob field stored as byte[]

public class Notes /*extends BaseAuditEntity */ implements Serializable {

private Long id;

private EspressoRichText richText;
//private byte[] richText;


@Embedded
public EspressoRichText getRichText() {
return richText;
}


public void setRichText(EspressoRichText richText) {
this.richText = richText;
}

.......
}

Here's how my EspressoRichText class looks like:


Code:
@Embeddable(/*access = AccessType.PROPERTY*/)
public class EspressoRichText /*extends BaseAuditEntity implements Serializable*/ {
   //private Long id;
   
   private byte[] data;

   @Transient
   public byte[] getData() {
      return data;
   }

   public void setData(byte[] data) {
      this.data = data;
   }
   
   @Lob
    @Column(name="DATA")
    @SuppressWarnings("unused")
    private Blob getDataBlob() {
     return Hibernate.createBlob(this.data);
    }
   
    @SuppressWarnings("unused")
    private void setDataBlob(Blob dataBlob) {
     this.data = this.toByteArray(dataBlob);
    }
/*
   @Id( generate=GeneratorType.SEQUENCE, generator="SEQ_STORE")
   @javax.persistence.SequenceGenerator (
         name="SEQ_STORE",
         sequenceName="ESPRESSO_RICH_TEXT_SEQ")
   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }
   */
   private byte[] toByteArray(Blob fromBlob) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
           return toByteArrayImpl(fromBlob, baos);
        } catch (SQLException e) {
           throw new RuntimeException(e);
        } catch (IOException e) {
           throw new RuntimeException(e);
        } finally {
         if (baos != null) {
          try {
                baos.close();
          } catch (IOException ex) {
          }
         }
        }
       }

       private byte[] toByteArrayImpl(Blob fromBlob, ByteArrayOutputStream baos)
        throws SQLException, IOException {
        byte[] buf = new byte[4000];
        InputStream is = fromBlob.getBinaryStream();
        try {
         for (;;) {
          int dataSize = is.read(buf);

          if (dataSize == -1)
           break;
          baos.write(buf, 0, dataSize);
         }
        } finally {
         if (is != null) {
          try {
           is.close();
          } catch (IOException ex) {
          }
         }
        }
        return baos.toByteArray();
       }
   
}


I've set the batch size in hibernate.properties as follows:
Code:
hibernate.jdbc.batch_size 0


In my test case, i'm doing the following:

Code:
Notes notes = new Notes();
              notes.setNotesName("test notes rich text");
              notes.setProduct(product);          
             EspressoRichText relRichText = new EspressoRichText();
                  
          
             relRichText.setData(this.getBytesFromFile(new File("config/applicationContext.xml")));
             notes.setRichText(relRichText);
                          notesDao.save(notes);


When i run the above junit test case, i get the following exception:

Code:
[junit] Testcase: testRichText(com.apple.ist.espresso.admin.dao.NotesDAOTest):      Caused an ERROR
    [junit] could not insert: [com.apple.ist.espresso.admin.model.Notes]
    [junit] org.hibernate.exception.GenericJDBCException: could not insert: [com.apple.ist.espresso.admin.model.Notes]
    [junit]     at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
    [junit]     at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
    [junit]     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    [junit]     at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1869)
    [junit]     at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2194)
    [junit]     at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
    [junit]     at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
    [junit]     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
    [junit]     at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
    [junit]     at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
    [junit]     at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    [junit]     at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
    [junit]     at com.apple.ist.espresso.util.DAOTestCase.tearDown(DAOTestCase.java:185)
    [junit]     at com.apple.ist.espresso.admin.dao.NotesDAOTest.tearDown(NotesDAOTest.java:88)
    [junit] Caused by: java.sql.SQLException: No more data to read from socket
    [junit]     at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    [junit]     at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    [junit]     at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1160)
    [junit]     at oracle.jdbc.ttc7.MAREngine.unmarshalUB1(MAREngine.java:963)
    [junit]     at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:893)
    [junit]     at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:375)
    [junit]     at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1894)
    [junit]     at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1094)
    [junit]     at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2132)
    [junit]     at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2015)
    [junit]     at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2877)
    [junit]     at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
    [junit]     at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
    [junit]     at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1853)
    [junit]     ... 20 more



Thanks a lot for any input on this!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 6:23 pm 
Regular
Regular

Joined: Tue Nov 09, 2004 5:15 pm
Posts: 100
After i upgraded to the latest jdbc drivers, this problem got resolved.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.