openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Goldner <mike.gold...@comcast.net>
Subject Problem reading persisted InputStream
Date Mon, 11 Aug 2008 04:18:03 GMT
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



Mime
View raw message