fixed bug 29910: exporting grid to csv can fail if audit fields are included
authorAsier Lostalé <asier.lostale@openbravo.com>
Tue, 10 Nov 2015 16:26:06 +0100
changeset 27850 c365fc9d4bd0
parent 27849 3a55fee4da9b
child 27851 a8ad0086de56
fixed bug 29910: exporting grid to csv can fail if audit fields are included

This error was caused by a partial initialization of audit elements in OBViewUtil,
when this occured and label for one of these elements was tried to be obtained,
LazyInitializationException was thrown.

It has been fixed by forcing complete initialization of the elements and their
translations.
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewUtil.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewUtil.java	Tue Nov 10 15:26:40 2015 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewUtil.java	Tue Nov 10 16:26:06 2015 +0100
@@ -23,6 +23,7 @@
 
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import org.hibernate.Hibernate;
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.client.application.GCField;
 import org.openbravo.client.application.GCSystem;
@@ -44,11 +45,24 @@
  * @author mtaal
  */
 public class OBViewUtil {
+  public static final Element createdElement;
+  public static final Element createdByElement;
+  public static final Element updatedElement;
+  public static final Element updatedByElement;
 
-  public static final Element createdElement = OBDal.getInstance().get(Element.class, "245");
-  public static final Element createdByElement = OBDal.getInstance().get(Element.class, "246");
-  public static final Element updatedElement = OBDal.getInstance().get(Element.class, "607");
-  public static final Element updatedByElement = OBDal.getInstance().get(Element.class, "608");
+  static {
+    createdElement = OBDal.getInstance().get(Element.class, "245");
+    createdByElement = OBDal.getInstance().get(Element.class, "246");
+    updatedElement = OBDal.getInstance().get(Element.class, "607");
+    updatedByElement = OBDal.getInstance().get(Element.class, "608");
+
+    // force loading translations for these fields as they might be used for labels
+    Hibernate.initialize(createdElement.getADElementTrlList());
+    Hibernate.initialize(createdByElement.getADElementTrlList());
+    Hibernate.initialize(updatedElement.getADElementTrlList());
+    Hibernate.initialize(updatedByElement.getADElementTrlList());
+  }
+
   private static Logger log = LoggerFactory.getLogger(OBViewUtil.class);
 
   /**