2 Replies Latest reply on Apr 9, 2006 5:05 PM by r_q_d

    multiple blob update operations hung up JBoss

      The blob code works fine when there is only one blob operation within one transaction, however, if the transaction includes several blob update operation, then the JBoss hungs up there.

      Here is my entity bean for blob

      package test;
      
      import java.io.ByteArrayOutputStream;
      import java.io.InputStream;
      import java.sql.Blob;
      import javax.persistence.Basic;
      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.Id;
      import javax.persistence.Lob;
      import javax.persistence.Table;
      import javax.persistence.Transient;
      
      import org.hibernate.Hibernate;
      
      @Entity
      @Table(name = "LongValue")
      public class LongValue {
      
       private Integer id;
      
       public LongValue() {
       }
      
       @Id
       public Integer getId() {
       return this.id;
       }
      
       public void setId(Integer id) {
       this.id = id;
       }
      
       private Blob theValue;
       @Lob @Basic(fetch=FetchType.LAZY)
       protected Blob getTheValue() {
       return theValue;
       }
      
       protected void setTheValue(Blob theValue) {
       this.theValue = theValue;
       }
      
       @Transient
       public void setValue(String aValue) throws Exception{
       this.theValue=Hibernate.createBlob(aValue.getBytes());
       }
      
       @Transient
       public String getValue() throws Exception{
       Blob blob=this.getTheValue();
       if(blob==null){
       return null;
       }
       int length=(int)blob.length();
       InputStream in=blob.getBinaryStream();
       ByteArrayOutputStream bout=new ByteArrayOutputStream(length);
       byte[] b=new byte[1000];
       while(true){
       length=in.read(b);
       if(length<0){
       break;
       }
       bout.write(b, 0, length);
       }
       in.close();
       bout.close();
       return new String(bout.toByteArray());
       }
      }
      


      This code will success because there is only one blob update:
       LongValue lv=manager.find(LongValue.class,id1 );
       lv.setValue(bigValue);
      


      This code will cause the jboss hung up there for unlimited time because there are several blob updates:
       LongValue lv=manager.find(LongValue.class,id1 );
       lv.setValue(bigValue+"1");
       lv=manager.find(LongValue.class,id2 );
       lv.setValue(bigValue+"2");
       lv=manager.find(LongValue.class,id3 );
       lv.setValue(bigValue+"3");
       lv=manager.find(LongValue.class,id4 );
       lv.setValue(bigValue+"4");