openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <>
Subject Re: Open JPA Persistence
Date Wed, 30 Mar 2011 18:13:42 GMT
Hi Elif,

By default OpenJPA obtains a connection for the duration of a singe
interaction with the database (e.g. one query or a single find operation).
The connection is then returned to the connection pool (if you have a
connection pool) and may be closed.

The openjpa.ConnectionRetainMode<>property
can be used to change this behavior and OpenJPA will hold on to a
single connection for the duration of a transaction, or until you close the

In particular the "always" setting should be used with care. If you do not
directly control the lifecycle of the EntityManager (e.g resource injection
from a JEE container) you may find that OpenJPA holds on to a connection for
a long time.

Hope this helps,

On Wed, Mar 30, 2011 at 12:05 PM, Elif Guner <> wrote:

> Hi there,
> We are converting our middleware piece to JEE and are using OpenJPA for
> persistence. However because of the existing database we cannot conform to
> persistence api fully. What we do is that we sometimes retrieve the
> Connection out of the EntityManager and execute a stored procedure. We are
> occasionally seeing errors such as "Statement already closed" although we
> never close the Connection ourselves. When we get the connection from
> EntityManager and use it to execute a procedure, we never close the
> connection as it is tied to the Entitymanager. We close the EntityManager
> at
> the end of our business methods. Can you please advise?
> Thanks,
> Elif Guner
> --
> *
> Never explain yourself to anyone.
> Because the person who likes you doesn't need it.
> And the person who dislikes you won't believe it.*

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