Backed out changeset 26214ce6e789
authorSandra Huguet <sandra.huguet@openbravo.com>
Wed, 05 Dec 2018 17:47:18 +0100
changeset 35212 616f94939565
parent 35211 c40f567a73a9
child 35213 e893c16b5687
Backed out changeset 26214ce6e789
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	Wed Dec 05 17:46:39 2018 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java	Wed Dec 05 17:47:18 2018 +0100
@@ -24,7 +24,10 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+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;
@@ -169,12 +172,7 @@
             && getConversionRateDocument(transaction).size() == 0) {
           insertConversionRateDocument(transaction);
         }
-
-        String financialAccountId = OBDal.getInstance().lockForNoKeyUpdate(
-            transaction.getAccount().getEntity(), transaction.getAccount().getId());
-        FIN_FinancialAccount financialAccount = OBDal.getInstance().get(FIN_FinancialAccount.class,
-            financialAccountId);
-
+        final FIN_FinancialAccount financialAccount = lockFinAccount(transaction.getAccount());
         financialAccount.setCurrentBalance(financialAccount.getCurrentBalance().add(
             transaction.getDepositAmount().subtract(transaction.getPaymentAmount())));
         transaction.setAprmProcessed("R");
@@ -244,11 +242,7 @@
           transaction.setStatus(transaction.getDepositAmount().compareTo(
               transaction.getPaymentAmount()) > 0 ? "RPR" : "PPM");
         }
-        String financialAccountId = OBDal.getInstance().lockForNoKeyUpdate(
-            transaction.getAccount().getEntity(), transaction.getAccount().getId());
-        FIN_FinancialAccount financialAccount = OBDal.getInstance().get(FIN_FinancialAccount.class,
-            financialAccountId);
-
+        final FIN_FinancialAccount financialAccount = lockFinAccount(transaction.getAccount());
         financialAccount.setCurrentBalance(financialAccount.getCurrentBalance()
             .subtract(transaction.getDepositAmount()).add(transaction.getPaymentAmount()));
         transaction.setAprmProcessed("P");
@@ -372,4 +366,17 @@
     }
     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();
+  }
 }