Related to ISSUE-42784: Code Review Changes:
authorDavid Miguelez <david.miguelez@openbravo.com>
Thu, 16 Jan 2020 17:13:15 +0100
changeset 36932 7fba53bcd24f
parent 36931 c449b2991a44
child 36933 d519ee911d4d
Related to ISSUE 42784: Code Review Changes:
* Simplify the call to the query object
* Use id instead of object in query
src/org/openbravo/event/CharacteristicValueEventHandler.java
--- a/src/org/openbravo/event/CharacteristicValueEventHandler.java	Tue Jan 14 07:50:35 2020 +0530
+++ b/src/org/openbravo/event/CharacteristicValueEventHandler.java	Thu Jan 16 17:13:15 2020 +0100
@@ -25,8 +25,6 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.hibernate.Session;
-import org.hibernate.query.Query;
 import org.hibernate.resource.transaction.spi.TransactionStatus;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
@@ -81,18 +79,18 @@
                  + "    select 1 "
                  + "    from  ProductCharacteristic as pc "
                  + "    where pcc.characteristicOfProduct = pc "
-                 + "    and pcc.characteristicValue = :characteristicValue "
+                 + "    and pcc.characteristicValue.id = :characteristicValueId "
                  + "    and pc.characteristicSubset is null "
                  + "    and pcc.code <> :code) ";
       //@formatter:on
       try {
-        final Session session = OBDal.getInstance().getSession();
-        @SuppressWarnings("rawtypes")
-        final Query charConfQuery = session.createQuery(hql);
-        charConfQuery.setParameter("user", OBContext.getOBContext().getUser());
-        charConfQuery.setParameter("characteristicValue", chv);
-        charConfQuery.setParameter("code", chv.getCode());
-        charConfQuery.executeUpdate();
+        OBDal.getInstance()
+            .getSession()
+            .createQuery(hql)
+            .setParameter("user", OBContext.getOBContext().getUser())
+            .setParameter("characteristicValueId", chv.getId())
+            .setParameter("code", chv.getCode())
+            .executeUpdate();
       } catch (Exception e) {
         logger.error(
             "Error on CharacteristicValueEventHandler. ProductCharacteristicConf could not be updated",