Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B5B946B0F for ; Sat, 28 May 2011 10:41:26 +0000 (UTC) Received: (qmail 19076 invoked by uid 500); 28 May 2011 10:41:26 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 19036 invoked by uid 500); 28 May 2011 10:41:25 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 19028 invoked by uid 99); 28 May 2011 10:41:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 May 2011 10:41:25 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [60.241.215.76] (HELO sudus.eu) (60.241.215.76) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 May 2011 10:41:19 +0000 Received: from [10.8.0.6] (unknown [10.8.0.6]) by sudus.eu (Postfix) with ESMTPA id A426346 for ; Sat, 28 May 2011 20:40:57 +1000 (EST) Subject: Suddenly byte-array returns NULL From: Walter Rugora To: users@openjpa.apache.org Content-Type: text/plain; charset="UTF-8" Date: Sat, 28 May 2011 20:40:56 +1000 Message-ID: <1306579256.1437.298.camel@ventus> Mime-Version: 1.0 X-Mailer: Evolution 2.32.2 Content-Transfer-Encoding: 7bit Hi there, so far I never had issues to read out of an array of bytes to display an image. Within the entity class the image field is specified as: @Lob private byte[] image; I read and write an image via: public Image getImage() { Data.EM.refresh(this); InputStream in = new ByteArrayInputStream(this.image); BufferedImage bu = null; try { bu = javax.imageio.ImageIO.read(in); } catch (Exception e) { } return bu; } public void setImage(Image image) { try { BufferedImage bu = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bu.createGraphics(); g2.drawImage(image, 0, 0, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bu, "png", baos); this.image = baos.toByteArray(); baos.close(); } catch (IOException ex) { Logger.getLogger(Imagereference.class.getName()).log(Level.SEVERE, null, ex); } } What is disturbing is that I suddenly cannot read the image from the derby database via OpenJPA. What I get in return as soon as I invoke getImage is an exception (Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0). When debugging it shows that getImage (this.image is NULL) returns Null. However, when I read out the data of the image column in the database table it is clearly not null but filled with an array of bytes. Btw. all other fields can be accessed without any problem via OpenJPA. Did someone experienced a similar problem? Thanks, Walter