Java Mailing List Archive

http://www.gg3721.com/

Home » users.openjpa »

Problem reading persisted InputStream

Michael Goldner

2008-08-11

Replies: Find Java Web Hosting

Author LoginPost Reply
I am trying to use the new lob streaming functionality in 1.1.0. My
database is Derby. Is Derby even supported for lob streaming? My initial
test is to simply write a file to Derby and then read it back out to disk.

I can save the stream to the db without any errors. However, when I attempt
to retrieve the instance I always get an error when I try to read from the
stream.

The basic code looks like this:

Write:

InstanceEntity instance = new InstanceEntity();
InputStream fis = new BufferedInputStream(new FileInputStream(file));
instance.setInstanceData(fis);
entityManager.persist(instance);

Read:

InstanceEntity instance = entityManager.find(InstanceEntity.class, id);
InputStream fis = (InputStream) instance.getInstanceData();
int b = fis.read();

I've tried a variety of InputStreams (FileInputStream, BufferedInputStream,
etc.) and they all seem to fail when I attempt to read() from them. Writing
the object to the db using a BufferedInputStream results in a
"java.io.IOException: Stream closed" on the read().

In the openjpa tests, I see some code for an InputStreamWrapper
(./openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/meta/strat
s/InputStreamWrapper.java). There seems to be some handling surrounding the
flushing of a stream. Is this related to (or a fix for) the issue I'm
encountering?

Thanks,

Mike


©2008 gg3721.com - Jax Systems, LLC, U.S.A.