public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     Liquidacion liquidacion;
     try {
       liquidacion = em.getReference(Liquidacion.class, id);
       liquidacion.getIdliquidacion();
     } catch (EntityNotFoundException enfe) {
       throw new NonexistentEntityException(
           "The liquidacion with id " + id + " no longer exists.", enfe);
     }
     List<String> illegalOrphanMessages = null;
     Collection<DescripcionLiquidacion> descripcionLiquidacionCollectionOrphanCheck =
         liquidacion.getDescripcionLiquidacionCollection();
     for (DescripcionLiquidacion
         descripcionLiquidacionCollectionOrphanCheckDescripcionLiquidacion :
             descripcionLiquidacionCollectionOrphanCheck) {
       if (illegalOrphanMessages == null) {
         illegalOrphanMessages = new ArrayList<String>();
       }
       illegalOrphanMessages.add(
           "This Liquidacion ("
               + liquidacion
               + ") cannot be destroyed since the DescripcionLiquidacion "
               + descripcionLiquidacionCollectionOrphanCheckDescripcionLiquidacion
               + " in its descripcionLiquidacionCollection field has a non-nullable liquidacionIdliquidacion field.");
     }
     Collection<ProductoaCambiar> productoacambiarCollectionOrphanCheck =
         liquidacion.getProductoacambiarCollection();
     for (ProductoaCambiar productoacambiarCollectionOrphanCheckProductoaCambiar :
         productoacambiarCollectionOrphanCheck) {
       if (illegalOrphanMessages == null) {
         illegalOrphanMessages = new ArrayList<String>();
       }
       illegalOrphanMessages.add(
           "This Liquidacion ("
               + liquidacion
               + ") cannot be destroyed since the ProductoaCambiar "
               + productoacambiarCollectionOrphanCheckProductoaCambiar
               + " in its productoacambiarCollection field has a non-nullable liquidacionIdliquidacion field.");
     }
     if (illegalOrphanMessages != null) {
       throw new IllegalOrphanException(illegalOrphanMessages);
     }
     Pedido pedidoIdpedido = liquidacion.getPedidoIdpedido();
     if (pedidoIdpedido != null) {
       pedidoIdpedido.getLiquidacionCollection().remove(liquidacion);
       pedidoIdpedido = em.merge(pedidoIdpedido);
     }
     em.remove(liquidacion);
     em.getTransaction().commit();
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }
 public void edit(ProductoaCambiar productoaCambiar) throws NonexistentEntityException, Exception {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     ProductoaCambiar persistentProductoaCambiar =
         em.find(ProductoaCambiar.class, productoaCambiar.getIdproductoacambiar());
     Liquidacion liquidacionIdliquidacionOld =
         persistentProductoaCambiar.getLiquidacionIdliquidacion();
     Liquidacion liquidacionIdliquidacionNew = productoaCambiar.getLiquidacionIdliquidacion();
     if (liquidacionIdliquidacionNew != null) {
       liquidacionIdliquidacionNew =
           em.getReference(
               liquidacionIdliquidacionNew.getClass(),
               liquidacionIdliquidacionNew.getIdliquidacion());
       productoaCambiar.setLiquidacionIdliquidacion(liquidacionIdliquidacionNew);
     }
     productoaCambiar = em.merge(productoaCambiar);
     if (liquidacionIdliquidacionOld != null
         && !liquidacionIdliquidacionOld.equals(liquidacionIdliquidacionNew)) {
       liquidacionIdliquidacionOld.getProductoacambiarCollection().remove(productoaCambiar);
       liquidacionIdliquidacionOld = em.merge(liquidacionIdliquidacionOld);
     }
     if (liquidacionIdliquidacionNew != null
         && !liquidacionIdliquidacionNew.equals(liquidacionIdliquidacionOld)) {
       liquidacionIdliquidacionNew.getProductoacambiarCollection().add(productoaCambiar);
       liquidacionIdliquidacionNew = em.merge(liquidacionIdliquidacionNew);
     }
     em.getTransaction().commit();
   } catch (Exception ex) {
     String msg = ex.getLocalizedMessage();
     if (msg == null || msg.length() == 0) {
       Integer id = productoaCambiar.getIdproductoacambiar();
       if (findProductoaCambiar(id) == null) {
         throw new NonexistentEntityException(
             "The productoaCambiar with id " + id + " no longer exists.");
       }
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }
 public void create(ProductoaCambiar productoaCambiar) {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     Liquidacion liquidacionIdliquidacion = productoaCambiar.getLiquidacionIdliquidacion();
     if (liquidacionIdliquidacion != null) {
       liquidacionIdliquidacion =
           em.getReference(
               liquidacionIdliquidacion.getClass(), liquidacionIdliquidacion.getIdliquidacion());
       productoaCambiar.setLiquidacionIdliquidacion(liquidacionIdliquidacion);
     }
     em.persist(productoaCambiar);
     if (liquidacionIdliquidacion != null) {
       liquidacionIdliquidacion.getProductoacambiarCollection().add(productoaCambiar);
       liquidacionIdliquidacion = em.merge(liquidacionIdliquidacion);
     }
     em.getTransaction().commit();
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }
 public void edit(Liquidacion liquidacion)
     throws IllegalOrphanException, NonexistentEntityException, Exception {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     Liquidacion persistentLiquidacion =
         em.find(Liquidacion.class, liquidacion.getIdliquidacion());
     Pedido pedidoIdpedidoOld = persistentLiquidacion.getPedidoIdpedido();
     Pedido pedidoIdpedidoNew = liquidacion.getPedidoIdpedido();
     Collection<DescripcionLiquidacion> descripcionLiquidacionCollectionOld =
         persistentLiquidacion.getDescripcionLiquidacionCollection();
     Collection<DescripcionLiquidacion> descripcionLiquidacionCollectionNew =
         liquidacion.getDescripcionLiquidacionCollection();
     Collection<ProductoaCambiar> productoacambiarCollectionOld =
         persistentLiquidacion.getProductoacambiarCollection();
     Collection<ProductoaCambiar> productoacambiarCollectionNew =
         liquidacion.getProductoacambiarCollection();
     List<String> illegalOrphanMessages = null;
     for (DescripcionLiquidacion descripcionLiquidacionCollectionOldDescripcionLiquidacion :
         descripcionLiquidacionCollectionOld) {
       if (!descripcionLiquidacionCollectionNew.contains(
           descripcionLiquidacionCollectionOldDescripcionLiquidacion)) {
         if (illegalOrphanMessages == null) {
           illegalOrphanMessages = new ArrayList<String>();
         }
         illegalOrphanMessages.add(
             "You must retain DescripcionLiquidacion "
                 + descripcionLiquidacionCollectionOldDescripcionLiquidacion
                 + " since its liquidacionIdliquidacion field is not nullable.");
       }
     }
     for (ProductoaCambiar productoacambiarCollectionOldProductoaCambiar :
         productoacambiarCollectionOld) {
       if (!productoacambiarCollectionNew.contains(
           productoacambiarCollectionOldProductoaCambiar)) {
         if (illegalOrphanMessages == null) {
           illegalOrphanMessages = new ArrayList<String>();
         }
         illegalOrphanMessages.add(
             "You must retain ProductoaCambiar "
                 + productoacambiarCollectionOldProductoaCambiar
                 + " since its liquidacionIdliquidacion field is not nullable.");
       }
     }
     if (illegalOrphanMessages != null) {
       throw new IllegalOrphanException(illegalOrphanMessages);
     }
     if (pedidoIdpedidoNew != null) {
       pedidoIdpedidoNew =
           em.getReference(pedidoIdpedidoNew.getClass(), pedidoIdpedidoNew.getIdpedido());
       liquidacion.setPedidoIdpedido(pedidoIdpedidoNew);
     }
     Collection<DescripcionLiquidacion> attachedDescripcionLiquidacionCollectionNew =
         new ArrayList<DescripcionLiquidacion>();
     for (DescripcionLiquidacion
         descripcionLiquidacionCollectionNewDescripcionLiquidacionToAttach :
             descripcionLiquidacionCollectionNew) {
       descripcionLiquidacionCollectionNewDescripcionLiquidacionToAttach =
           em.getReference(
               descripcionLiquidacionCollectionNewDescripcionLiquidacionToAttach.getClass(),
               descripcionLiquidacionCollectionNewDescripcionLiquidacionToAttach
                   .getIdDescripcionLiquidacion());
       attachedDescripcionLiquidacionCollectionNew.add(
           descripcionLiquidacionCollectionNewDescripcionLiquidacionToAttach);
     }
     descripcionLiquidacionCollectionNew = attachedDescripcionLiquidacionCollectionNew;
     liquidacion.setDescripcionLiquidacionCollection(descripcionLiquidacionCollectionNew);
     Collection<ProductoaCambiar> attachedProductoacambiarCollectionNew =
         new ArrayList<ProductoaCambiar>();
     for (ProductoaCambiar productoacambiarCollectionNewProductoaCambiarToAttach :
         productoacambiarCollectionNew) {
       productoacambiarCollectionNewProductoaCambiarToAttach =
           em.getReference(
               productoacambiarCollectionNewProductoaCambiarToAttach.getClass(),
               productoacambiarCollectionNewProductoaCambiarToAttach.getIdproductoacambiar());
       attachedProductoacambiarCollectionNew.add(
           productoacambiarCollectionNewProductoaCambiarToAttach);
     }
     productoacambiarCollectionNew = attachedProductoacambiarCollectionNew;
     liquidacion.setProductoacambiarCollection(productoacambiarCollectionNew);
     liquidacion = em.merge(liquidacion);
     if (pedidoIdpedidoOld != null && !pedidoIdpedidoOld.equals(pedidoIdpedidoNew)) {
       pedidoIdpedidoOld.getLiquidacionCollection().remove(liquidacion);
       pedidoIdpedidoOld = em.merge(pedidoIdpedidoOld);
     }
     if (pedidoIdpedidoNew != null && !pedidoIdpedidoNew.equals(pedidoIdpedidoOld)) {
       pedidoIdpedidoNew.getLiquidacionCollection().add(liquidacion);
       pedidoIdpedidoNew = em.merge(pedidoIdpedidoNew);
     }
     for (DescripcionLiquidacion descripcionLiquidacionCollectionNewDescripcionLiquidacion :
         descripcionLiquidacionCollectionNew) {
       if (!descripcionLiquidacionCollectionOld.contains(
           descripcionLiquidacionCollectionNewDescripcionLiquidacion)) {
         Liquidacion
             oldLiquidacionIdliquidacionOfDescripcionLiquidacionCollectionNewDescripcionLiquidacion =
                 descripcionLiquidacionCollectionNewDescripcionLiquidacion
                     .getLiquidacionIdliquidacion();
         descripcionLiquidacionCollectionNewDescripcionLiquidacion.setLiquidacionIdliquidacion(
             liquidacion);
         descripcionLiquidacionCollectionNewDescripcionLiquidacion =
             em.merge(descripcionLiquidacionCollectionNewDescripcionLiquidacion);
         if (oldLiquidacionIdliquidacionOfDescripcionLiquidacionCollectionNewDescripcionLiquidacion
                 != null
             && !oldLiquidacionIdliquidacionOfDescripcionLiquidacionCollectionNewDescripcionLiquidacion
                 .equals(liquidacion)) {
           oldLiquidacionIdliquidacionOfDescripcionLiquidacionCollectionNewDescripcionLiquidacion
               .getDescripcionLiquidacionCollection()
               .remove(descripcionLiquidacionCollectionNewDescripcionLiquidacion);
           oldLiquidacionIdliquidacionOfDescripcionLiquidacionCollectionNewDescripcionLiquidacion =
               em.merge(
                   oldLiquidacionIdliquidacionOfDescripcionLiquidacionCollectionNewDescripcionLiquidacion);
         }
       }
     }
     for (ProductoaCambiar productoacambiarCollectionNewProductoaCambiar :
         productoacambiarCollectionNew) {
       if (!productoacambiarCollectionOld.contains(
           productoacambiarCollectionNewProductoaCambiar)) {
         Liquidacion oldLiquidacionIdliquidacionOfProductoacambiarCollectionNewProductoaCambiar =
             productoacambiarCollectionNewProductoaCambiar.getLiquidacionIdliquidacion();
         productoacambiarCollectionNewProductoaCambiar.setLiquidacionIdliquidacion(liquidacion);
         productoacambiarCollectionNewProductoaCambiar =
             em.merge(productoacambiarCollectionNewProductoaCambiar);
         if (oldLiquidacionIdliquidacionOfProductoacambiarCollectionNewProductoaCambiar != null
             && !oldLiquidacionIdliquidacionOfProductoacambiarCollectionNewProductoaCambiar.equals(
                 liquidacion)) {
           oldLiquidacionIdliquidacionOfProductoacambiarCollectionNewProductoaCambiar
               .getProductoacambiarCollection()
               .remove(productoacambiarCollectionNewProductoaCambiar);
           oldLiquidacionIdliquidacionOfProductoacambiarCollectionNewProductoaCambiar =
               em.merge(
                   oldLiquidacionIdliquidacionOfProductoacambiarCollectionNewProductoaCambiar);
         }
       }
     }
     em.getTransaction().commit();
   } catch (Exception ex) {
     String msg = ex.getLocalizedMessage();
     if (msg == null || msg.length() == 0) {
       Integer id = liquidacion.getIdliquidacion();
       if (findLiquidacion(id) == null) {
         throw new NonexistentEntityException(
             "The liquidacion with id " + id + " no longer exists.");
       }
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }