openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Giblin <...@zurich.ibm.com>
Subject Re: Cannot close EntityManager
Date Fri, 09 Apr 2010 08:08:26 GMT
If an exception occurs in remove(), the transaction is still open when the
finally block is performed.
Check whether the trans is active and roll it back if so, as in the
following:

} finally {
  if (em != null) {
     if (em.getTransaction().isActive()) {
        em.getTransaction().rollback();
      }
      em.close();
   }
}

-chris



                                                                           
             Cil-Gamir                                                     
             <hannes.visagie@r                                             
             mb.co.za>                                                  To 
                                       users@openjpa.apache.org            
             04/09/2010 09:23                                           cc 
             AM                                                            
                                                                   Subject 
                                       Cannot close EntityManager          
             Please respond to                                             
             users@openjpa.apa                                             
                  che.org                                                  
                                                                           
                                                                           
                                                                           





Hi

I have this piece of code

        EntityManager em = emf.getEntityManager();
        try {
                em.getTransaction().begin();
                em.remove(kycRequestTempDocumentsToDelete);
                em.getTransaction().commit();
        } finally {
            if (em != null) {
                em.close();
            }
        }

I cannot seem to make that em.close call, it tells me that the transaction
is still active.

I use an em-per-request and that's the end of that request, so I would
really like to close it.

The application runs on tomcat and will likely not be restarted in months,
is it ok to leave the em open, this method gets called thousands of times a
day.

Any advice on how to close it ?
--
View this message in context:
http://n2.nabble.com/Cannot-close-EntityManager-tp4875727p4875727.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.



Mime
View raw message