Fixes issue 33627: debug call in OBCriteria.count does trigger extra db query in some case
authorMartin Taal <martin.taal@openbravo.com>
Sun, 07 Aug 2016 16:24:38 +0200
changeset 30068 2f8cbe2f7611
parent 30067 ae1076c7e9ea
child 30069 8a76d197db69
child 30074 768f34426413
Fixes issue 33627: debug call in OBCriteria.count does trigger extra db query in some case
Wrap log.debug in if statement
src/org/openbravo/dal/service/OBCriteria.java
--- a/src/org/openbravo/dal/service/OBCriteria.java	Thu Aug 04 16:07:56 2016 +0200
+++ b/src/org/openbravo/dal/service/OBCriteria.java	Sun Aug 07 16:24:38 2016 +0200
@@ -100,7 +100,13 @@
   public int count() {
     initialize();
     setProjection(Projections.rowCount());
-    log.debug("Counting using criteria " + toString());
+    /*
+     * check for debug first, as toString() does initialize some hibernate proxies of other entities
+     * used in the criteria
+     */
+    if (log.isDebugEnabled()) {
+      log.debug("Counting using criteria " + toString());
+    }
     final int result = ((Number) uniqueResult()).intValue();
     setProjection(null);
     return result;