details:   https://code.openbravo.com/erp/devel/pi/rev/1f961fdb2035
changeset: 31565:1f961fdb2035
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Mon Feb 27 10:50:16 2017 +0100
summary:   fixes bug 35356: print & attach doc logs error using (old) commons 
jdbc pool

After closing a connection retrieved from the Hibernate pool, it is marked as 
not usable. It is not possible to check the status of such connections because 
a HibernateException is thrown.

After printing a report which makes use of the getCountryNumberFormat and 
applyCountryDateFormat methods of the Utility class, the connection is closed 
to prevent possible connection leaks. Therefore, when using the Hibernate pool, 
the connection is marked as not usable causing the HibernateException when 
checking the status of the connection after printing the report.

To fix the problem now we are handling the HibernateException and initializing 
the connection properly.

diffstat:

 src/org/openbravo/service/db/DalConnectionProvider.java |  6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diffs (23 lines):

diff -r e7630e80f729 -r 1f961fdb2035 
src/org/openbravo/service/db/DalConnectionProvider.java
--- a/src/org/openbravo/service/db/DalConnectionProvider.java   Mon Feb 27 
10:40:30 2017 +0100
+++ b/src/org/openbravo/service/db/DalConnectionProvider.java   Mon Feb 27 
10:50:16 2017 +0100
@@ -27,6 +27,7 @@
 import java.sql.Statement;
 import java.util.Properties;
 
+import org.hibernate.HibernateException;
 import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.dal.core.SessionHandler;
 import org.openbravo.dal.service.OBDal;
@@ -95,6 +96,11 @@
       }
     } catch (SQLException sqlex) {
       log.error("Error checking connection of {} pool", pool, sqlex);
+    } catch (HibernateException hex) {
+      // Handle the case of a connection retrieved from Hibernate pool which 
has been already
+      // closed. In this case the connection is marked as not usable and when 
we try to check its
+      // status a HibernateException is thrown.
+      connection = OBDal.getInstance(pool).getConnection(flush);
     }
 
     // always flush all remaining actions

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to