diff --git a/src/org/openbravo/costing/CostingMigrationProcess.java b/src/org/openbravo/costing/CostingMigrationProcess.java
--- a/src/org/openbravo/costing/CostingMigrationProcess.java
+++ b/src/org/openbravo/costing/CostingMigrationProcess.java
@@ -284,10 +284,11 @@
           updateTrxLegacyCosts(cost, stdPrecission, naturalTree);
 
           if ((i % 100) == 0) {
-            SessionHandler.getInstance().commitAndStart();
+            OBDal.getInstance().flush();
             OBDal.getInstance().getSession().clear();
           }
         }
+        SessionHandler.getInstance().commitAndStart();
       }
     }
 
@@ -585,9 +586,9 @@
         // Shipments with accounting date different than the movement date gets the cost valid on
         // the accounting date.
         BigDecimal unitCost = new BigDecimal(new ProductInfo(cost.getProduct().getId(),
-            new DalConnectionProvider()).getProductItemCost(OBDateUtils.formatDate(trx
+            new DalConnectionProvider(false)).getProductItemCost(OBDateUtils.formatDate(trx
             .getGoodsShipmentLine().getShipmentReceipt().getAccountingDate()), null, "AV",
-            new DalConnectionProvider(), OBDal.getInstance().getConnection()));
+            new DalConnectionProvider(false), OBDal.getInstance().getConnection()));
         BigDecimal trxCost = unitCost.multiply(trx.getMovementQuantity().abs()).setScale(
             standardPrecision, BigDecimal.ROUND_HALF_UP);
 
