openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Walter Rugora <m...@sudus.eu>
Subject Suddenly byte-array returns NULL
Date Sat, 28 May 2011 10:40:56 GMT
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


Mime
View raw message