public OrderPurchase createNewOrder(OrderPurchase orderPurchase) { if (orderPurchase.getDateCreate() == null) { orderPurchase.setDateCreate(new Date()); } orderPurchase.setDateUpdate(new Date()); if (orderPurchase.getId() == null) { orderPurchase = createNewOrderWithRightOrderNumber(orderPurchase); } return orderPurchase; }
public OrderPurchase saveOrUpdateOrder(OrderPurchase orderPurchase) { if (orderPurchase.getDateCreate() == null) { orderPurchase.setDateCreate(new Date()); } orderPurchase.setDateUpdate(new Date()); // if (orderPurchase.getId() != null) { // if(em.contains(orderPurchase)){ // em.refresh(orderPurchase); // } // OrderPurchase mergedOrderPurchase = em.merge(orderPurchase); // em.flush(); // return mergedOrderPurchase; // } else { // em.persist(orderPurchase); // return orderPurchase; // } if (em.contains(orderPurchase)) { em.refresh(orderPurchase); } OrderPurchase mergedOrderPurchase = em.merge(orderPurchase); em.flush(); return mergedOrderPurchase; }