Hi I'm working on a ejb application which has a database table to store
files as 'bytea' datatype in a postgres database.
My first try was to read the files into a byte[] on the client and call the
setData(byte[] b) method on the written entity bean. This works great for
small files, but if the files get bigger ( some mb ) this results in an out
of memory error in JBoss. The better way would be to use Streams to read
and write the data to the database, but i don't know how to access the
streams in the entity-bean from the client, as rmi can only transfer
serializable objects, but not streams.
Has anybody done this before or has a simple answer how to handle this?
Thanks in advance
Johannes Hermen
Luxembourg
Joost Kraaijeveld - 10 May 2005 12:21 GMT
> Hi I'm working on a ejb application which has a database table to store
> files as 'bytea' datatype in a postgres database.
[quoted text clipped - 6 lines]
> serializable objects, but not streams.
> Has anybody done this before or has a simple answer how to handle this?
Have you looked at ResultSet.getBinaryStream()?
Joost
Johannes Hermen - 10 May 2005 12:52 GMT
> Have you looked at ResultSet.getBinaryStream()?
Yes, sure, thats not the problem. the thing is how to access the stream from
outside the entity bean on the client site.
Greets
Johannes Hermen
Joost Kraaijeveld - 10 May 2005 13:12 GMT
>>Have you looked at ResultSet.getBinaryStream()?
>
> Yes, sure, thats not the problem. the thing is how to access the stream from
> outside the entity bean on the client site.
Ah, than why don't you implement the needed part of an InputStream's
interface in your bean as a wrapper around the BinaryStream?
Joost Kraaijeveld - 10 May 2005 13:26 GMT
>>> Have you looked at ResultSet.getBinaryStream()?
>>
[quoted text clipped - 4 lines]
> Ah, than why don't you implement the needed part of an InputStream's
> interface in your bean as a wrapper around the BinaryStream?
In response to my own remark: because transient fields do not survive a
passivation/activation process as one might expect as they are
serialized in the process.
Mmm. Store it in an MBean?
robertP - 10 May 2005 17:26 GMT
Wait. If you want the client to access the data as a stream and work
with it as such, why are you using EJB?! The point of EJB is to hide
the internal format of the data, and allow you to work with the data as
objects. That's not what you want, so I'd reccomend dumping the EJB and
going with simple DAO/JavaBeans.
Joost Kraaijeveld - 10 May 2005 18:20 GMT
> Wait. If you want the client to access the data as a stream and work
> with it as such, why are you using EJB?! The point of EJB is to hide
> the internal format of the data, and allow you to work with the data as
> objects. That's not what you want, so I'd reccomend dumping the EJB and
> going with simple DAO/JavaBeans.
We also have int, string, floats etc. An OutputAtream in itself is just
a datatype. Probably for a large Word file, bitmap or JPEG file as an
attribute of an object (or the main part of the object itself) which is
implented as a blob in a database.
CodeFutures - 11 May 2005 22:33 GMT
Are you sure that EJB CMP is the best strategy?
While using DAOs is without doubt the best architecture, you may like
to look at POJOs - maybe JDBC DAOs?
You can read some more about the technology choices here:
http://www.codefutures.com/weblog/corporate/archives/2005/02/data_persistenc.html
I've seen similar projects with a very simple JDBC DAOs - with lots of
blobs.