예제 #1
0
  @SuppressWarnings("unchecked")
  public List<Itens_Venda> listar() {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    List<Itens_Venda> itens = null;

    try {
      Query consulta = sessao.getNamedQuery("Itens_Venda.listar");
      itens = consulta.list();

    } catch (RuntimeException ex) {
      throw ex;
    } finally {
      sessao.close();
    }

    return itens;
  }
예제 #2
0
  public void excluir(Itens_Venda itens_venda) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Transaction transacao = null;

    try {
      transacao = sessao.beginTransaction();
      sessao.delete(itens_venda);
      transacao.commit();

    } catch (RuntimeException ex) {
      if (transacao != null) {
        transacao.rollback();
      }

    } finally {
      sessao.close();
    }
  }
예제 #3
0
  public Itens_Venda buscarPorCodigo(Long id) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Itens_Venda item = null;

    try {
      Query consulta = sessao.getNamedQuery("Itens_Venda.buscarPorCodigo");
      consulta.setLong("id", id);

      item = (Itens_Venda) consulta.uniqueResult();

    } catch (RuntimeException ex) {
      throw ex;
    } finally {
      sessao.close();
    }

    return item;
  }