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<http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_dbsetup_retain>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 EntityManager. 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, -mike On Wed, Mar 30, 2011 at 12:05 PM, Elif Guner <[email protected]> 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.* > > LE TEMPS DETRUIT TOUT >
