0 Replies Latest reply on May 6, 2006 6:45 AM by Leos Urban

    @Lob on postgresql does not save first byte

    Leos Urban Newbie

      Hi,
      I have the following experience:

      I created entity bean with @Lob field:

       // Binary based Large Object
       @Lob @Basic(fetch = FetchType.EAGER)
       public byte[] getPhoto()
       {
       return photo;
       }
       public void setPhoto(byte[] photo)
       {
       this.photo = photo;
       }
      


      Bug? in @Lob implementation or PostgresqlDialect
      First byte of binary data are not saved.
       File file = new File("/home/lur/picture.jpg");
       b = new byte[ (int) file.length() ];
       FileInputStream fis = new FileInputStream(file);
       fis.read(b);
       fis.close();
       o.setPhoto(b);
       riStockItems.save(o);
      


      And workaround (works fine):
       // Workaround - JBOSS/EJB3+PGSQL ignores first byte of array
       File file = new File("/home/lur/picture.jpg");
       b = new byte[ (int) file.length()+1 ]; // we need one more byte
       FileInputStream fis = new FileInputStream(file);
       fis.read(b,1,(int) file.length()); // we begin from second byte
       fis.close();
       o.setPhoto(b);
       riStockItems.save(o);
      


      What other SQL servers (hibernate dialects)?

      Leonell