openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <michael.d.d...@gmail.com>
Subject Re: Close database connection
Date Thu, 09 Jul 2009 14:28:26 GMT
Hi Annette,

I think on-demand is the default value for ConnectionRetainMode, so you
*shouldn't* need to set the property. I don't see how it could hurt though.

Making sure you close the em before it goes out of scope is definitely a
good idea (same would go for the EntityManagerFactory, but that has a longer
scope). You might not want to close the em after every operation though -
just when you're done using it (ie before it goes out of scope).

Hope this helps,

-mike

On Thu, Jul 9, 2009 at 8:08 AM, Scherer, Annette <
Annette.Scherer@huk-coburg.de> wrote:

> Hello Michael,
>
> Thank you for your tip.
> I think, I do not use em.close() after very each operation on DB
>
> Should I additionally configure the ConnectionRetainMode property in my
> persistence.xml (Suppose not, for on-demand is the default configuration for
> ConnectionRetainMode)
>
> Actual version
> ....
> <properties>
>        <property name="openjpa.TransactionMode" value="managed"/>
>        <property name="openjpa.ConnectionFactoryMode" value="managed"/>
>        <property name="openjpa.jdbc.DBDictionary" value="db2"/>
>        <property name="openjpa.jdbc.Schema" value="T7"/>
> </properties>
> ......
>
>
> Improved version
> ....
> <properties>
>        <property name="openjpa.TransactionMode" value="managed"/>
>        <property name="openjpa.ConnectionFactoryMode" value="managed"/>
>        <property name="openjpa.ConnectionRetainMode" value="on-demand"/>
>        <property name="openjpa.jdbc.DBDictionary" value="db2"/>
>        <property name="openjpa.jdbc.Schema" value="T7"/>
> </properties>
> ....
>
>
>
> Annette Scherer
> Abteilung Informatik
>
> HUK-COBURG
> Bahnhofsplatz
> 96444 Coburg
> Telefon  09561 96-1718
> Telefax  09561 96-3671
> E-Mail   Annette.Scherer@HUK-COBURG.de
> Internet www.HUK.de
> =============================================================
> HUK-COBURG Haftpflicht-Unterstützungs-Kasse kraftfahrender Beamter
> Deutschlands a. G. in Coburg
> Reg.-Gericht Coburg HRB 100; St.-Nr. 9212/101/00021
> Sitz der Gesellschaft: Bahnhofsplatz, 96444 Coburg
> Vorsitzender des Aufsichtsrats: Werner Strohmayr.
> Vorstand: Dr. Wolfgang Weiler (Sprecher), Wolfgang Flaßhoff, Stefan
> Gronbach, Klaus-Jürgen Heitmann, Dr. Christian Hofer.
> =============================================================
>
>
> -----Ursprüngliche Nachricht-----
> Von: Michael Dick [mailto:michael.d.dick@gmail.com]
> Gesendet: Mittwoch, 8. Juli 2009 16:15
> An: users@openjpa.apache.org
> Betreff: Re: Cloese database connection
>
> Hi Annette,
>
> Are you using container managed EntityManagers, or application managed EMs?
>
> It *sounds* like you the EntityManager isn't being closed.
>
> To answer your specific question the connection is opened the first time
> you
> interact with the database (ie execute a query, or persist an entity). When
> it's closed depends on the ConnectionRetainMode setting [1] (looks like
> you're using 'always').
>
> [1]
>
> http://openjpa.apache.org/builds/1.2.1/apache-openjpa-1.2.1/docs/manual/manual.html#ref_guide_dbsetup_retain
>
> HTH
> -mike
>
> On Wed, Jul 8, 2009 at 8:12 AM, Scherer, Annette <
> Annette.Scherer@huk-coburg.de> wrote:
>
> > Hello,
> >
> > I am using OpenJPA with managed transactions and connections on an IBM
> > WebSphere Application Server.
> >
> > Extract from persistence.xml:
> > <property name="openjpa.TransactionMode" value="managed"/>
> > <property name="openjpa.ConnectionFactoryMode" value="managed"/>
> >
> > Configuration WAS:
> > JDBC - datasources - non XA connection
> >
> >
> > When does a managed connection open and when does it close?
> > My problem is that many connections will be opened that are never closed
> > again. Even if I shut down the Server, the connections remain open.
> >
> >
> > Thank you for help
> > Annette Scherer
> >
> >
> > Abteilung Informatik
> >
> >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message