27 Jul
JPA Oopsies (Lingering Open Connections)
Say you’re happily coding along and getting ready to call a PL/SQL package. You fire up your trusty EntityManager and slap a new query together…
em = EmFactory.getEntityManager(authentication);
em.getTransaction().begin();
StoredProcedureCall call = new StoredProcedureCall();
ValueReadQuery query = new ValueReadQuery();
All pretty standard stuff so far. Anyway, you slap a call together and execute it:
Integer i = (Integer) ((JpaEntityManager)em.getDelegate()).getActiveSession().executeQuery(query,args);
The query executes. You’re pretty happy, and move on. But then it gets into TEST and your SA starts pounding his chest and threatening bodily harm because there’s a slew of connections lingering open, and that just ain’t gonna work.
Anyway, the problem is right here:
em.getTransaction().begin();
You can call em.close() all you’d like, but Oracle seems to keep the connection open even after the work has been performed; and for good reason, since there’s a lingering transaction just floating out there.
So if your project is out in an environment and you start getting flooded with this error…
Caused by: java.sql.SQLException: ORA-02391: exceeded simultaneous SESSIONS_PER_USER limit
…then check all of your logic methods and make sure that all of your transactions are closed. All you need is one line at the end of the stored procedure call:
em.getTransaction().commit();
Now you know. Or know even more so. Or are reminded. Or something. Enjoy.
Ever since picking up my laptop, I have had a concern about having my stories on such a portable machine. I bought myself a Bauer-like man-purse, so this laptop basically goes everywhere I do. It’s convenient with the lappy being so light, but it IS a laptop. It’s not hard to take, mount the drive on an external system, and voila… all my stuff is in the open.