public TblMaterial getBasicInfo(String noParte) {
    Query query =
        em.createQuery(
            "SELECT  c.idtblMaterial,c.noParte,c.nombre,c.descripcion,c.stock,c.costo,c.imagen, c.idArea.idArea, c.idTipomaterial.idTipomaterial,c.subFamiliasidsubFam.idsubFam, c.idArea.descripcion, c.idTipomaterial.descripcion, c.subFamiliasidsubFam.nombre  FROM TblMaterial c WHERE c.noParte = :noParte");
    query.setParameter("noParte", noParte);

    Object[] object = (Object[]) query.getSingleResult();
    TblMaterial temp = new TblMaterial();
    temp.setIdtblMaterial((Integer) object[0]);
    temp.setNoParte((String) (object[1]));
    temp.setNombre((String) (object[2]));
    temp.setDescripcion((String) (object[3]));
    temp.setStock((Integer) (object[4]));
    temp.setCosto((Long) (object[5]));
    temp.setImagen((String) (object[6]));

    TblArea area = new TblArea((Integer) (object[7]));
    area.setDescripcion((String) object[10]);
    temp.setIdArea(area);

    TblTipomaterial tipo = new TblTipomaterial((Integer) (object[8]));
    tipo.setDescripcion((String) object[11]);
    temp.setIdTipomaterial(tipo);

    Subfamilias sub = new Subfamilias((Integer) (object[9]));
    sub.setNombre((String) object[12]);
    temp.setSubFamiliasidsubFam(sub);

    return temp;
  }
  private List<TblMaterial> mtlResults(Query query) {
    List<TblMaterial> data = new ArrayList<>();
    List list = query.getResultList();
    for (Iterator it = list.iterator(); it.hasNext(); ) {
      Object[] object = (Object[]) it.next();
      TblMaterial temp = new TblMaterial();
      temp.setIdtblMaterial((Integer) object[0]);
      temp.setNoParte((String) (object[1]));
      temp.setNombre((String) (object[2]));
      temp.setDescripcion((String) (object[3]));
      temp.setStock((Integer) (object[4]));
      temp.setCosto((Long) (object[5]));
      temp.setImagen((String) (object[6]));

      TblArea area = new TblArea((Integer) (object[7]));
      area.setDescripcion((String) object[10]);
      temp.setIdArea(area);

      TblTipomaterial tipo = new TblTipomaterial((Integer) (object[8]));
      tipo.setDescripcion((String) object[11]);
      temp.setIdTipomaterial(tipo);

      Subfamilias sub = new Subfamilias((Integer) (object[9]));
      sub.setNombre((String) object[12]);
      temp.setSubFamiliasidsubFam(sub);
      temp.setInventariable((Boolean) object[13]);
      data.add(temp);
    }
    return data;
  }
  public boolean agregar(
      String nombre,
      String noParte,
      String descripcion,
      String cantidad,
      String costo,
      String unidadmedida,
      String marca,
      String serie,
      String estado,
      String ubicacion,
      String responsable,
      String probedor,
      String noFactura,
      String ordenDcompra,
      String zip,
      String financiamiento,
      String tipodecompra,
      String idUABC,
      String fecharecepcion,
      String area,
      String tipodematerial,
      String subfamilia,
      String almacen,
      String imagen) {

    try {
      TblMaterial mat = new TblMaterial();
      TblArea ar = new TblArea();
      TblTipomaterial tm = new TblTipomaterial();
      Subfamilias sf = new Subfamilias();
      Almacen al = new Almacen();
      Date date1 = new Date();
      mat.setNombre(nombre);
      mat.setNoParte(noParte);
      mat.setDescripcion(descripcion);
      mat.setStock(Integer.parseInt(cantidad));
      mat.setCosto(Long.valueOf(costo));
      mat.setUnidadMedida(unidadmedida);
      mat.setMarca(marca);
      mat.setSerie(serie);
      mat.setEstado(estado);
      mat.setUbicacionActual(ubicacion);
      mat.setResponsable(responsable);
      mat.setProveedor(probedor);
      mat.setNumeroFactura(noFactura);
      mat.setOrdenCompra(ordenDcompra);
      mat.setCodigoSip(zip);
      mat.setFinanciamiento(financiamiento);
      mat.setTipoCompra(tipodecompra);
      mat.setIdUabc(idUABC);
      mat.setFechaRecepcion(date1);
      mat.setImagen(imagen);
      ar.setIdArea(Integer.parseInt(area));
      al.setIdalmacen(Integer.parseInt(almacen));
      tm.setIdTipomaterial(Integer.parseInt(tipodematerial));
      sf.setIdsubFam(Integer.parseInt(subfamilia));

      mat.setAlmacenIdalmacen(al);
      mat.setIdTipomaterial(tm);
      mat.setSubFamiliasidsubFam(sf);
      mat.setIdArea(ar);

      em.persist(mat);

      return true;
    } catch (Exception e) {
      return false;
    }
  }