Fix for issue 41849: Cannot post a document if it has customized SQL description
authorMark Molina <mark.molina@doceleguas.com>
Wed, 18 Sep 2019 21:49:30 -0300
changeset 36563 45f5100585a8
parent 36562 b75877805a1a
child 36564 8c33062c4a20
Fix for issue 41849: Cannot post a document if it has customized SQL description
that returns more than one record.

When the customized SQL description returned more than one record, an exception
was thrown because the query was executed expecting an unique result.

Now is executed with getResultList and all the resultant descriptions are append
to the description.
src/org/openbravo/erpCommon/ad_forms/FactLine.java
--- a/src/org/openbravo/erpCommon/ad_forms/FactLine.java	Mon Sep 09 12:07:53 2019 -0400
+++ b/src/org/openbravo/erpCommon/ad_forms/FactLine.java	Wed Sep 18 21:49:30 2019 -0300
@@ -19,6 +19,7 @@
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.sql.Connection;
+import java.util.List;
 
 import javax.servlet.ServletException;
 
@@ -1132,16 +1133,18 @@
         strSql = strSql.replaceAll("@RecordId@", ":paramRecordId")
             .replaceAll("@Line@", ":paramLineId");
 
-        @SuppressWarnings("rawtypes")
-        NativeQuery query = OBDal.getInstance().getSession().createSQLQuery(strSql);
+        @SuppressWarnings("unchecked")
+        NativeQuery<String> query = OBDal.getInstance().getSession().createSQLQuery(strSql);
         if (strSql.contains(":paramRecordId")) {
           query.setParameter("paramRecordId", strRecord_ID);
         }
         if (strSql.contains(":paramLineId")) {
           query.setParameter("paramLineId", StringUtils.isBlank(strLine) ? "NULL" : strLine);
         }
-        final String result = (String) query.uniqueResult();
-        description.append(StringUtils.defaultIfBlank(result, StringUtils.EMPTY));
+        List<String> descriptions = query.getResultList();
+        for (String desc : descriptions) {
+          description.append(StringUtils.defaultIfBlank(desc, StringUtils.EMPTY));
+        }
       }
       if (description.length() == 0) {
         description.append((m_docVO.DocumentNo == null) ? "" : m_docVO.DocumentNo);