fixed issue 39754 use the new method getObjectLockForNoKeyUpdate
authorSandra Huguet <sandra.huguet@openbravo.com>
Tue, 11 Dec 2018 17:44:03 +0100
changeset 35284 59876bd4506b
parent 35283 19193a2a5b15
child 35285 9ea275f262ba
fixed issue 39754 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	Tue Dec 11 17:43:07 2018 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java	Tue Dec 11 17:44:03 2018 +0100
@@ -22,9 +22,6 @@
 import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
-import org.hibernate.LockOptions;
-import org.hibernate.Query;
-import org.hibernate.Session;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.advpaymentmngt.APRM_FinaccTransactionV;
 import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
@@ -172,7 +169,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");
@@ -242,7 +240,8 @@
           transaction.setStatus(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");
@@ -366,16 +365,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 query = session.createQuery(queryStr.toString());
-    query.setParameter("id", account.getId());
-    query.setMaxResults(1);
-    query.setLockOptions(LockOptions.UPGRADE);
-    OBDal.getInstance().getSession().evict(account);
-    return (FIN_FinancialAccount) query.uniqueResult();
-  }
 }