Пример #1
0
 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;
 }
Пример #2
0
  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;
  }