diff --git a/src/org/openbravo/costing/AverageCostAdjustment.java b/src/org/openbravo/costing/AverageCostAdjustment.java
--- a/src/org/openbravo/costing/AverageCostAdjustment.java
+++ b/src/org/openbravo/costing/AverageCostAdjustment.java
@@ -97,7 +97,6 @@
       if (!costAdjLine.getId().equals(strCostAdjLineId)) {
         costAdjLine.setParentCostAdjustmentLine(baseCAL);
       }
-      OBDal.getInstance().save(costAdjLine);
       // If the cost adjustment line has Transaction Costs those adjustment amount are included
       // in the Current Value Amount and not in the Adjustment Balance
       if (!costAdjLine.getTransactionCostList().isEmpty()) {
@@ -177,7 +176,6 @@
         Date newDate = new Date();
         Date dateTo = costing.getEndingDate();
         costing.setEndingDate(newDate);
-        OBDal.getInstance().save(costing);
         Costing newCosting = OBProvider.getInstance().get(Costing.class);
         newCosting.setCost(cost);
         newCosting.setCurrency((Currency) OBDal.getInstance().getProxy(Currency.ENTITY_NAME,
@@ -213,7 +211,6 @@
             || (curCosting.getTotalStockValuation() != null && curCosting.getTotalStockValuation()
                 .compareTo(currentValueAmt.add(adjustmentBalance)) != 0)) {
           curCosting.setPermanent(Boolean.FALSE);
-          OBDal.getInstance().save(curCosting);
           OBDal.getInstance().flush();
           // Update existing costing
           if (curCosting.getCost().compareTo(cost) != 0) {
@@ -227,7 +224,6 @@
           curCosting.setTotalStockValuation(null);
           curCosting.setPermanent(Boolean.TRUE);
           OBDal.getInstance().flush();
-          OBDal.getInstance().save(curCosting);
         }
       }
     }
@@ -290,7 +286,6 @@
           existingCAL.setParentCostAdjustmentLine((CostAdjustmentLine) OBDal.getInstance()
               .getProxy(CostAdjustmentLine.ENTITY_NAME, strCostAdjLineId));
 
-          OBDal.getInstance().save(existingCAL);
         }
         log.debug("Current trx adj amount of existing CALs {}", trxAdjAmt.toPlainString());
 
@@ -412,7 +407,6 @@
           } else {
             // Update existing costing
             curCosting.setPermanent(Boolean.FALSE);
-            OBDal.getInstance().save(curCosting);
             OBDal.getInstance().flush();
             if (curCosting.getCost().compareTo(cost) != 0) {
               if (curCosting.getOriginalCost() == null) {
@@ -506,7 +500,6 @@
       if (currentCosting.getCost().compareTo(cost) != 0) {
         // Update existing costing
         currentCosting.setPermanent(Boolean.FALSE);
-        OBDal.getInstance().save(currentCosting);
         OBDal.getInstance().flush();
 
         if (currentCosting.getOriginalCost() == null) {
@@ -518,7 +511,6 @@
         currentCosting.setTotalStockValuation(null);
         currentCosting.setManual(Boolean.FALSE);
         currentCosting.setPermanent(Boolean.TRUE);
-        OBDal.getInstance().save(currentCosting);
       }
     }
   }
diff --git a/src/org/openbravo/costing/CostAdjustmentProcess.java b/src/org/openbravo/costing/CostAdjustmentProcess.java
--- a/src/org/openbravo/costing/CostAdjustmentProcess.java
+++ b/src/org/openbravo/costing/CostAdjustmentProcess.java
@@ -245,7 +245,6 @@
       // Reload cost adjustment object in case the costing algorithm has cleared the session.
       line = OBDal.getInstance().get(CostAdjustmentLine.class, strCostAdjLineId);
       line.setRelatedTransactionAdjusted(true);
-      OBDal.getInstance().save(line);
       OBDal.getInstance().flush();
       generateTransactionCosts(line);
       OBDal.getInstance().flush();
@@ -308,14 +307,15 @@
         }
         trxCost.setCost(convertedAmt);
         trxCost.setCurrency(trx.getCurrency());
+        OBDal.getInstance().getSession().evict(trx);
 
         OBDal.getInstance().save(trxCost);
-        OBDal.getInstance().flush();
-        OBDal.getInstance().getSession().clear();
       }
     } finally {
       lines.close();
     }
+    OBDal.getInstance().flush();
+    OBDal.getInstance().getSession().clear();
     log.debug("Transaction costs created. Time {}", System.currentTimeMillis() - t1);
   }
 
diff --git a/src/org/openbravo/costing/CostAdjustmentUtils.java b/src/org/openbravo/costing/CostAdjustmentUtils.java
--- a/src/org/openbravo/costing/CostAdjustmentUtils.java
+++ b/src/org/openbravo/costing/CostAdjustmentUtils.java
@@ -119,6 +119,14 @@
   public static CostAdjustmentLine insertCostAdjustmentLine(MaterialTransaction transaction,
       CostAdjustment costAdjustmentHeader, BigDecimal costAdjusted, boolean isSource,
       Date accountingDate) {
+    Long lineNo = getNewLineNo(costAdjustmentHeader);
+    return insertCostAdjustmentLine(transaction, costAdjustmentHeader, costAdjusted, isSource,
+        accountingDate, lineNo);
+  }
+
+  public static CostAdjustmentLine insertCostAdjustmentLine(MaterialTransaction transaction,
+      CostAdjustment costAdjustmentHeader, BigDecimal costAdjusted, boolean isSource,
+      Date accountingDate, Long lineNo) {
     Long stdPrecission = transaction.getCurrency().getStandardPrecision();
     CostAdjustmentLine costAdjustmentLine = OBProvider.getInstance().get(CostAdjustmentLine.class);
     costAdjustmentLine.setOrganization(costAdjustmentHeader.getOrganization());
@@ -133,7 +141,7 @@
     costAdjustmentLine.setInventoryTransaction(transaction);
     costAdjustmentLine.setSource(isSource);
     costAdjustmentLine.setAccountingDate(accountingDate);
-    costAdjustmentLine.setLineNo(getNewLineNo(costAdjustmentHeader));
+    costAdjustmentLine.setLineNo(lineNo);
 
     OBDal.getInstance().save(costAdjustmentLine);
 
@@ -265,11 +273,10 @@
 
   private static Long getNewLineNo(CostAdjustment cadj) {
     StringBuffer where = new StringBuffer();
-    where.append(" select " + CostAdjustmentLine.PROPERTY_LINENO);
+    where.append(" select max(" + CostAdjustmentLine.PROPERTY_LINENO + ")");
     where.append(" from " + CostAdjustmentLine.ENTITY_NAME + " as cal");
     where.append(" where cal." + CostAdjustmentLine.PROPERTY_COSTADJUSTMENT
         + ".id = :costAdjustment");
-    where.append(" order by cal." + CostAdjustmentLine.PROPERTY_LINENO + " desc");
     Query calQry = OBDal.getInstance().getSession().createQuery(where.toString());
     calQry.setParameter("costAdjustment", cadj.getId());
     calQry.setMaxResults(1);
diff --git a/src/org/openbravo/costing/CostingAlgorithmAdjustmentImp.java b/src/org/openbravo/costing/CostingAlgorithmAdjustmentImp.java
--- a/src/org/openbravo/costing/CostingAlgorithmAdjustmentImp.java
+++ b/src/org/openbravo/costing/CostingAlgorithmAdjustmentImp.java
@@ -26,6 +26,7 @@
 
 import javax.enterprise.context.Dependent;
 
+import org.hibernate.Query;
 import org.hibernate.ScrollMode;
 import org.hibernate.ScrollableResults;
 import org.hibernate.criterion.Restrictions;
@@ -73,6 +74,7 @@
   protected boolean isManufacturingProduct;
   protected boolean areBackdatedTrxFixed;
   protected boolean checkNegativeStockCorrection;
+  protected Long nextLineNo;
   protected HashMap<CostDimension, String> costDimensionIds = new HashMap<CostDimension, String>();
 
   /**
@@ -229,17 +231,33 @@
 
     CostAdjustmentLine newCAL = CostAdjustmentUtils.insertCostAdjustmentLine(trx,
         (CostAdjustment) OBDal.getInstance().getProxy(CostAdjustment.ENTITY_NAME, strCostAdjId),
-        adjustmentamt, false, dateAcct);
+        adjustmentamt, false, dateAcct, getNextLineNo());
     newCAL.setRelatedTransactionAdjusted(false);
     newCAL.setParentCostAdjustmentLine(parentLine);
 
     OBDal.getInstance().save(newCAL);
-    OBDal.getInstance().flush();
 
     addCostDependingTrx(newCAL);
     return newCAL;
   }
 
+  private Long getNextLineNo() {
+    if (nextLineNo == null) {
+      StringBuffer where = new StringBuffer();
+      where.append(" select max(" + CostAdjustmentLine.PROPERTY_LINENO + ")");
+      where.append(" from " + CostAdjustmentLine.ENTITY_NAME + " as cal");
+      where.append(" where cal." + CostAdjustmentLine.PROPERTY_COSTADJUSTMENT
+          + ".id = :costAdjustment");
+      Query calQry = OBDal.getInstance().getSession().createQuery(where.toString());
+      calQry.setParameter("costAdjustment", strCostAdjId);
+      calQry.setMaxResults(1);
+
+      nextLineNo = (Long) calQry.uniqueResult();
+    }
+    nextLineNo += 10L;
+    return nextLineNo;
+  }
+
   /**
    * When the cost of a Closing Inventory is adjusted it is needed to adjust with the same amount
    * the related Opening Inventory.
