-->
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.  [ 3 posts ] 
Author Message
 Post subject: Oracle IOException when working with Blobs over 1MB
PostPosted: Mon Dec 15, 2008 12:31 pm 
Newbie

Joined: Mon Dec 15, 2008 10:45 am
Posts: 2
I am trying to insert images selected by a user from an applet. I can insert images over 100K without any issue. When I select an image from the browser that is over 1MB I get an IOException when trying to write to the DB.

I have done a lot of research on this issue and I have searched the forums before making this post.

The database is 10g and I am using Oracle 10.1.0.5 Type 4 driver in classes12.zip provided by Oracle. This is standard driver by my company for our setup and I cannot switch to the Type 3 ojdbc14 driver.

I am also using WebSphere in RAD 7.0.0.5

I am using WebSphere's connection pooling which is setup via the plig-in tag in my struts-config file. I use the JNDI lookup to get the transaction manager. This has been working fine so far.

I am using hibernate 3.3.1

I used the approach to inserting blobs into the database discussed at:
http://hansonchar.blogspot.com/2005/06/oracle-blob-mapped-to-byte-in.html

This is my Java Object:

Code:

public class CaseStudyPictureBook implements java.io.Serializable{

    private static final long serialVersionUID = 3041874046189597595L;
    private Long pictureId;
    private Long caseStudyId;
    private String description;
    private byte[] picture;
    private String createdBy;
    private java.sql.Date createdDate;
    private String modifiedBy;
    private java.sql.Date modifiedDate;
    private Long pictureCategoryId;
    private CaseStudyPictureCategoryLookup csStatus;
   
   
    public CaseStudyPictureBook(){
   super();
    }


    public Long getCaseStudyId() {
        return this.caseStudyId;
    }


    public void setCaseStudyId(Long caseStudyId) {
        this.caseStudyId = caseStudyId;
    }


    public String getCreatedBy() {
        return this.createdBy;
    }


    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }


    public java.sql.Date getCreatedDate() {
        return this.createdDate;
    }


    public void setCreatedDate(java.sql.Date createdDate) {
        this.createdDate = createdDate;
    }


    public String getDescription() {
        return this.description;
    }


    public void setDescription(String description) {
        this.description = description;
    }


    public String getModifiedBy() {
        return this.modifiedBy;
    }


    public void setModifiedBy(String modifiedBy) {
        this.modifiedBy = modifiedBy;
    }


    public java.sql.Date getModifiedDate() {
        return this.modifiedDate;
    }


    public void setModifiedDate(java.sql.Date modifiedDate) {
        this.modifiedDate = modifiedDate;
    }


    public Long getPictureId() {
        return this.pictureId;
    }


    public void setPictureId(Long pictureId) {
        this.pictureId = pictureId;
    }


    public Long getPictureCategoryId() {
        return this.pictureCategoryId;
    }


    public void setPictureCategoryId(Long pictureCategoryId) {
        this.pictureCategoryId = pictureCategoryId;
    }


    public CaseStudyPictureCategoryLookup getCsStatus() {
        return this.csStatus;
    }


    public void setCsStatus(CaseStudyPictureCategoryLookup csStatus) {
        this.csStatus = csStatus;
    }

   
   
    public byte[] getPicture() {
        return this.picture;
    }


    public void setPicture(byte[] picture) {
        this.picture = picture;
    }


    /** Don't invoke this.  Used by Hibernate only. */
    public void setImageBlob(Blob imageBlob) { 
   this.picture = this.toByteArray(imageBlob);
    }
   
    /** Don't invoke this.  Used by Hibernate only. */     
    public Blob getImageBlob() { 
   return Hibernate.createBlob(this.picture);
    }
   
    private byte[] toByteArray(Blob fromBlob) { 
      ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
   try {   
       return toByteArrayImpl(fromBlob, baos); 
   } catch (java.sql.SQLException e) {   
       throw new RuntimeException(e); 
      } catch (java.io.IOException e) {   
          throw new RuntimeException(e); 
          }
         finally {   
             if (baos != null) {   
            try {   
                baos.close();   
                } catch (java.io.IOException ex) {   
               ex.printStackTrace();
                }   
             } 
      }
    }
    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 (java.io.IOException ex) {   
            
         }   
         } 
      } 
       return baos.toByteArray();
    }
}


This is my mapping file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="com.centimark.casestudy.dto.CaseStudyPictureBook" table="CASE_STUDY_PICTURE_BOOK" dynamic-update="true" dynamic-insert="true">
<id name="pictureId" type="long" column="PICTURE_ID" >
   <generator class="increment">
   </generator>
</id>      

<property name="caseStudyId"  column="CASE_STUDY_ID" />
<property name="description"    column="DESCRIPTION"/>
<property name="picture"    column="PICTURE" type="binary"/>
<property name="createdBy"    column="CREATED_BY"/>
<property name="createdDate"    column="CREATED_DATE"/>
<property name="modifiedBy"    column="MODIFIED_BY"/>
<property name="modifiedDate" column="MODIFIED_DATE"/>
<property name="pictureCategoryId" column="PICTURE_CATEGORY_ID" insert="true" update="true"/>
      
<many-to-one name="csStatus"  column="PICTURE_CATEGORY_ID" not-null="true" lazy="false" insert="false" update="false" cascade="none" foreign-key="FK_PICTURE_CATEGORY_ID"/>

</class>
</hibernate-mapping>


This is my exception:

[12/15/08 10:12:23:531 EST] 0000002a SystemErr R 1167844 [WebContainer : 1] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 17002, SQLState: null
[12/15/08 10:12:23:531 EST] 0000002a SystemErr R 1167844 [WebContainer : 1] ERROR org.hibernate.util.JDBCExceptionReporter - Io exception: Connection reset by peer: socket write error
[12/15/08 10:12:23:531 EST] 0000002a SystemErr R 1167844 [WebContainer : 1] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 17002, SQLState: null
[12/15/08 10:12:23:531 EST] 0000002a SystemErr R 1167844 [WebContainer : 1] ERROR org.hibernate.util.JDBCExceptionReporter - Io exception: Connection reset by peer: socket write error
[12/15/08 10:12:23:531 EST] 0000002a SystemErr R 1167844 [WebContainer : 1] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
[12/15/08 10:12:23:531 EST] 0000002a SystemErr R org.hibernate.exception.GenericJDBCException: could not insert: [com.centimark.casestudy.dto.CaseStudyPictureBook]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2295)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2682)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at com.centimark.casestudy.service.CaseStudySavePicturesService.execute(CaseStudySavePicturesService.java:58)
at com.centimark.casestudy.servlets.ImageUploadServlet.doTask(ImageUploadServlet.java:89)
at com.centimark.casestudy.servlets.ImageUploadServlet.doPost(ImageUploadServlet.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:989)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:501)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:464)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3276)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:267)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1455)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:113)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:454)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:383)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:263)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:195)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:743)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:873)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1469)
Caused by: com.ibm.websphere.ce.cm.StaleConnectionException: Io exception: Connection reset by peer: socket write error
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:67)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:521)
at com.ibm.websphere.rsadapter.GenericDataStoreHelper.mapExceptionHelper(GenericDataStoreHelper.java:523)
at com.ibm.websphere.rsadapter.GenericDataStoreHelper.mapException(GenericDataStoreHelper.java:578)
at com.ibm.ws.rsadapter.jdbc.WSJdbcUtil.mapException(WSJdbcUtil.java:903)
at com.ibm.ws.rsadapter.jdbc.WSJdbcPreparedStatement.executeUpdate(WSJdbcPreparedStatement.java:626)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2275)
... 34 more
[12/15/08 10:12:23:531 EST] 0000002a SystemErr R Failed to insert pictures.org.hibernate.exception.GenericJDBCException: could not insert: [com.centimark.casestudy.dto.CaseStudyPictureBook]


Any help is appreciated. Please let me know if I need to supply any more information or if there are any questions.

Thank you in advance,

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2009 2:10 pm 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
Did you figure out this one ? Heard that some people that had a similar issue mentioned that a driver upgrade fixed the issue...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2009 2:13 pm 
Newbie

Joined: Mon Dec 15, 2008 10:45 am
Posts: 2
I wrote an interface that bypassed hibernate when dealing with Blobs. My company set the constraint that I could not upgrade the drivers on the production server at this time.


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