Related to ISSUE-43051. Code Review changes:
authorDavid Miguelez <david.miguelez@openbravo.com>
Fri, 07 Feb 2020 11:32:08 +0100
changeset 37031 a917cf43f5c8
parent 37030 bfcc801da2e8
child 37032 6140b72f414d
Related to ISSUE 43051. Code Review changes:
* Use id's instead of objects in hql queries
* Changed variable names to better reflect that they
refer to an id.
src/org/openbravo/costing/CostingRuleProcessOnProcessHandler.java
--- a/src/org/openbravo/costing/CostingRuleProcessOnProcessHandler.java	Thu Jan 30 12:10:00 2020 +0100
+++ b/src/org/openbravo/costing/CostingRuleProcessOnProcessHandler.java	Fri Feb 07 11:32:08 2020 +0100
@@ -133,7 +133,7 @@
     //@formatter:off
     final String hql =
                   "as cr" +
-                  " where cr.organization = :ruleOrg" +
+                  " where cr.organization.id = :ruleOrgId" +
                   "   and cr.validated = true" +
                   " order by cr.startingDate desc";
     //@formatter:on
@@ -141,30 +141,31 @@
     return OBDal.getInstance()
         .createQuery(CostingRule.class, hql)
         .setFilterOnReadableOrganization(false)
-        .setNamedParameter("ruleOrg", rule.getOrganization())
+        .setNamedParameter("ruleOrgId", rule.getOrganization().getId())
         .setMaxResult(1)
         .uniqueResult();
   }
 
-  private boolean existsTransactions(final Set<String> naturalOrgs, final Set<String> childOrgs) {
+  private boolean existsTransactions(final Set<String> naturalOrgIds,
+      final Set<String> childOrgIds) {
     //@formatter:off
     final String hql =
                   "as p" +
                   " where p.productType = 'I'" +
                   "   and p.stocked = true" +
-                  "   and p.organization.id in (:porgs)" +
+                  "   and p.organization.id in (:productOrgIds)" +
                   "   and exists (" +
                   "     select 1 from MaterialMgmtMaterialTransaction" +
-                  "      where product = p" +
-                  "        and organization .id in (:childOrgs)" +
+                  "      where product.id = p.id" +
+                  "        and organization .id in (:childOrgIds)" +
                   "     )";
     //@formatter:on
 
     return OBDal.getInstance()
         .createQuery(Product.class, hql)
         .setFilterOnReadableOrganization(false)
-        .setNamedParameter("porgs", naturalOrgs)
-        .setNamedParameter("childOrgs", childOrgs)
+        .setNamedParameter("productOrgIds", naturalOrgIds)
+        .setNamedParameter("childOrgIds", childOrgIds)
         .setMaxResult(1)
         .uniqueResult() != null;
   }