Hi Patrick / others,

I know this thread is a bit old but I hope someone replies. Here's the line
of interest to me

>>quote
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.

>>end quote

I'm currently working with a scenario where I'm using DBUnit for testing.
Dbunit uses raw JDBC connections for its needs. I'm getting separate JDBC
connections for this. However, I chose to leave the connection open as I
want to manage performance for a larger test suite. 

For openJPA I'm using a pattern where I bind the entity manager to a
ThreadLocal object so that repeated calls to getTransaction(),
getEntityManager() return me the same object (a pattern I picked up from my
earlier work in Hibernate). 

Now this seems to throw up weird errors, JPA does not seem to behave as it
should. The moment I close the earlier JDBC connection (used for DBUnit
stuff), it works fine. I've read and digged enuff to conclude that this is a
threading issue and that somewhere the "Connection" bound to the current
thread is causing the problem.

However, I can't explain the entire behaviour to myself (not knowing JPA
internals). Could someone throw light on this. Also, I need a pattern where
I can reuse the JDBC connection. Is this possible at all ?

Right now, I'm gonna probably just resign to my fate and close the
underlying connection....

Please read my post which has the code I've spoken about.

http:// 
http://n2.nabble.com/open-connections-causing-strange-behaviour-td661614.html 








Patrick Linskey-2 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?
> 
> -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
>>
> 
> 
> 
> -- 
> Patrick Linskey
> 202 669 5907
> 
> 

-- 
View this message in context: 
http://n2.nabble.com/How-to-get-I-get-to-the-read-JDBC-Connection-object...-tp210473p663764.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to