On Monday 31 March 2008, Patrick Linskey wrote:
> > The manual suggests:-
> >
> > OpenJPAEntityManagerFactory kemf = OpenJPAPersistence.cast(emf);
> > OpenJPAConfiguration conf = kemf.getConfiguration();
> >
> > on page 190, but kemf does not have a getConfiguration method according
> > to Eclipse (using OpenJPA 1.0.2).
>
> Oops; that's out-of-date. Getting the Configuration isn't part of the
> published APIs. In addition, that documentation shows how to find a
> separate connection, not the one currently in use by the EM.
>
> For what you've described, you should use
> OpenJPAEntityManager.getConnection() and cast the returned object to a
> Connection. The returned connection is a wrapper; you may need to dig
> through it to get to the underlying Connection if you need to use
> Postgres-specific methods.
>
> Don't forget to close() the connection when you're done with it --
> OpenJPA does reference counting on the connections it doles out in
> order to properly handle the ConnectionRetainMode setting.
>
> Out of curiosity, what types of large object stuff do you need to do?
I want to use the PGConnection to get a LargeObjectManager, and then
to create a LargeObject, which I can then read and write. These are
media objects, which I will then stream to a player, and which I really do
not want to load into memory all at once. So in my JPA managed object
I will just keep the oid, and then I will use the code above to get the
real data.
I found a way of doing it, but it involves a xxxSPI method which I guess
I should not be using:-
OpenJPAEntityManagerFactorySPI kemf = (OpenJPAEntityManagerFactorySPI)
OpenJPAPersistence.cast(emf);
OpenJPAConfiguration conf = kemf.getConfiguration();
DataSource ds = (DataSource)conf.getConnectionFactory();
DelegatingConnection delconn =
(DelegatingConnection)ds.getConnection("david", "");
Connection conn = delconn.getInnermostDelegate();
PGConnection pgconn = (PGConnection)delconn.getInnermostDelegate();
I need the Connection as well as the PGConnection as I can not
setAutoCommit on a PGConnection.
It would be better to get the actual connection being used for the transaction
in which I persist the object containing the oid, as then the same commit
and rollback would apply to both the persist of the JPA object and the
LargeObject, but if I can not have it I will have to busk it and garbage
collect the LargeObjects from time to time.
David
>
> -Patrick
>
> On Mon, Mar 31, 2008 at 7:15 AM, David Goodenough
>
> <[EMAIL PROTECTED]> wrote:
> > I need to get to the real JDBC Connection object so that I can do some
> > processing using Postgresql extensions (in particular the LargeObject
> > support). I do not expect OpenJPA to understand what I am doing, but
> > I need to access the Connection object and I need what I do to be
> > in the same transaction as that used by OpenJPA (so also it needs to
> > be the same transaction).
> >
> > The manual suggests:-
> >
> > OpenJPAEntityManagerFactory kemf = OpenJPAPersistence.cast(emf);
> > OpenJPAConfiguration conf = kemf.getConfiguration();
> >
> > on page 190, but kemf does not have a getConfiguration method according
> > to Eclipse (using OpenJPA 1.0.2).
> >
> > The OpenJPAConfiguration javadoc is not much use either in that it does
> > tell me where to get it from.
> >
> > Any ideas?
> >
> > David