fixed issue 39753 use the new method getObjectLockForNoKeyUpdate
authorSandra Huguet <sandra.huguet@openbravo.com>
Tue, 11 Dec 2018 17:18:05 +0100
changeset 35290 71014553054c
parent 35211 9a7acd649cfc
child 35291 440fd243a83c
fixed issue 39753 use the new method getObjectLockForNoKeyUpdate
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java	Mon Dec 10 05:42:41 2018 +0000
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java	Tue Dec 11 17:18:05 2018 +0100
@@ -22,10 +22,7 @@
 import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
-import org.hibernate.LockOptions;
-import org.hibernate.Session;
 import org.hibernate.criterion.Restrictions;
-import org.hibernate.query.Query;
 import org.openbravo.advpaymentmngt.APRM_FinaccTransactionV;
 import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
@@ -173,7 +170,8 @@
             && getConversionRateDocument(transaction).size() == 0) {
           insertConversionRateDocument(transaction);
         }
-        final FIN_FinancialAccount financialAccount = lockFinAccount(transaction.getAccount());
+        FIN_FinancialAccount financialAccount = OBDal.getInstance().getObjectLockForNoKeyUpdate(
+            transaction.getAccount());
         financialAccount.setCurrentBalance(financialAccount.getCurrentBalance()
             .add(transaction.getDepositAmount().subtract(transaction.getPaymentAmount())));
         transaction.setAprmProcessed("R");
@@ -245,7 +243,8 @@
               transaction.getDepositAmount().compareTo(transaction.getPaymentAmount()) > 0 ? "RPR"
                   : "PPM");
         }
-        final FIN_FinancialAccount financialAccount = lockFinAccount(transaction.getAccount());
+        FIN_FinancialAccount financialAccount = OBDal.getInstance().getObjectLockForNoKeyUpdate(
+            transaction.getAccount());
         financialAccount.setCurrentBalance(financialAccount.getCurrentBalance()
             .subtract(transaction.getDepositAmount()).add(transaction.getPaymentAmount()));
         transaction.setAprmProcessed("P");
@@ -370,17 +369,4 @@
     }
     return confirmation;
   }
-
-  private static FIN_FinancialAccount lockFinAccount(FIN_FinancialAccount account) {
-    StringBuilder queryStr = new StringBuilder(
-        "select a from FIN_Financial_Account a where id = :id");
-    final Session session = OBDal.getInstance().getSession();
-    final Query<FIN_FinancialAccount> query = session.createQuery(queryStr.toString(),
-        FIN_FinancialAccount.class);
-    query.setParameter("id", account.getId());
-    query.setMaxResults(1);
-    query.setLockOptions(LockOptions.UPGRADE);
-    OBDal.getInstance().getSession().evict(account);
-    return query.uniqueResult();
-  }
 }