Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Blob and PostgreSQL

FWIW I've done this sort of thing using JDBC instead of JPA for this very reason so I'm interested the JPA solution.  

I ran into something similar with HSQL.  In that case I ended up unwrapping the Eclipselink session from the injected EntityManager, getting a connection and creating a prepared statement whose ResultSet I iterated, grabbing the blob stream like so:

InputStream myBlobStream = resultSet.getBlob(6).getBinaryStream();

For my model I went with a byte[] property since Blob is an interface.  I too noticed Eclipselink generating DDL w/LONGVARBINARY for @Lob fields w/HSQL even though this defeats how HSQL stores BLOBS. In the case of HSQL it will store BLOBS in a separate file if the column is BLOB, if the column is LONGVARBINARY it stores them with the rest of the DB data. Which in HSQL's case has pretty big implications. 

-Noah

On Jun 24, 2013, at 4:12 PM, Andreas Joseph Krogh <andreak@xxxxxxxxxxxx> wrote:

På mandag 24. juni 2013 kl. 21:57:22, skrev Tom Ware <tom.ware@xxxxxxxxxx>:
Lets say you get a LOB using an OID.  Does the connection you initially read it
with need to stay open in order to get the stream?  (If so, that will be a
challenge given the constraints of the JPA world).  If not, what code would you
write to get the stream?  Do you keep the stream open for a long period of time?
  Do you need a connection for the duration of the time that you use it?
 
What I need is large files (not fit in RAM) to be part of a transaction when writing data. The streams won't be open for any longer than the time it takes to read/write the data.
 
I come from the Hibernate world and I'm heading for porting our app to EL as Hibernate gives us  way too much trouble. But in order to do this I have a sample-app where I test stuff so that I'm sure stuff works the way I want before porting the app (~190K JAVA code and 90K Scala-code).
 
When it comes to handelign LOBs I need something like this:
 
For retreival:
doInTransaction{
MyEntity e = myRepository.find(PK)
StreamUtils.copy(e.getBlob.getBinaryStream, outputStream)
}
 
For creation (Hibernate pseudo-code):
doInTransaction{
            LobHelper lobHelper = session.getLobHelper
            Blob blob = lobHelper.createBlob(f.fileStream, f.length)
            myEntity.setBlob(blob)
}
 
PG's jdbc-driver doesn't implement Connection.createBlob so Hibernate uses a BlobProxy (org.hibernate.engine.jdbc.BlobProxy) which does goes around this.
 
Are there any examples around using PG with Blobs, using streams (not byte[]) ?
 
--
Andreas Joseph Krogh <andreak@xxxxxxxxxxxx>      mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc
 
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top