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; }
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);
// 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);