Example usage for org.hibernate Session createQuery

List of usage examples for org.hibernate Session createQuery

Introduction

In this page you can find the example usage for org.hibernate Session createQuery.

Prototype

@Override
    org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);

Source Link

Usage

From source file:br.com.clinica.dao.ProntuarioDao.java

public List<Prontuario> busca(String nome, String campo) {
    System.out.println("Entrou Busca");
    Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
    ss.beginTransaction();/*  ww  w . j  a  v a  2s .c om*/
    List lista = ss.createQuery("From prontuario p where p." + campo + " = '" + nome + "'").list();
    ss.getTransaction().commit();
    //ss.close();
    return lista;

}

From source file:br.com.clinica.dao.UsuarioDao.java

public List<Usuario> list() {
    Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
    ss.beginTransaction();/*w  w  w.j a  v a 2s.  com*/
    List lista = ss.createQuery("From usuario ").list();
    ss.getTransaction().commit();
    return lista;
}

From source file:br.com.dao.UsuarioImp.java

public List<Usuario> list() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = session.beginTransaction();
    List lista = session.createQuery("from Usuario").list();
    t.commit();//from ww  w .j  ava 2  s .  com
    return lista;
}

From source file:br.com.gaiatosfc.DAO.AdversariosDAOImp.java

@Override
public List<Adversarios> findAllJogadores() throws DAOException {
    Session session = null;
    try {//from  ww w.  j  a va2  s  .  com
        session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        List allAdversarios = session.createQuery("from Adversarios A order by A.nome asc").list();
        t.commit();
        return allAdversarios;
    } catch (Exception e) {
        throw new DAOException("Nenhum Jogador localizado: " + e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:br.com.gaiatosfc.DAO.CampeonatosDAOImp.java

@Override
public List<Jogadores> findAllCampeonatos() throws DAOException {
    Session session = null;
    try {/*from   w  ww  .  ja va 2s  .c om*/
        session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        List allCampeonatos = session.createQuery("from campeonatos C order by C.nome_camp asc").list();
        t.commit();
        return allCampeonatos;
    } catch (Exception e) {
        throw new DAOException("Nenhum Campeonato Cadastrao " + e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:br.com.gaiatosfc.DAO.JogadoresDAOImp.java

@Override
public List<Jogadores> findAllJogadores() throws DAOException {
    Session session = null;
    try {//from  w ww  .j a  v  a 2s  . c  om
        session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        List allJogadores = session.createQuery("FROM Jogadores J order by J.nomeJd asc").list();
        t.commit();
        return allJogadores;
    } catch (Exception e) {
        throw new DAOException("Nenhum Jogador Cadastrado: " + e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:br.com.gaiatosfc.DAO.JogadoresDAOImp.java

public List<String> findAllNumeroCamisa() throws DAOException {
    Session session = null;
    try {//from   w ww . j  a  v a2s  .c o m
        session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        List allnumeroCamisa = session
                .createQuery("SELECT J.numeroCamisa FROM Jogadores J ORDER BY J.numeroCamisa asc").list();
        t.commit();
        return allnumeroCamisa;
    } catch (Exception e) {
        throw new DAOException("Nenhum Jogador Cadastrado: " + e);
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:br.com.jn.dao.CandidatoDAO.java

public List<Candidato> listarCalculada() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = session.beginTransaction();
    List lista = session.createQuery("from candiato").list();
    t.commit();/*from  w  w  w. j a va2 s .c  o  m*/
    return lista;
}

From source file:br.com.livraria.dao.VendaDAO.java

public List<Venda> buscar(VendaFilter filtro) {
    List<Venda> vendas = null;

    StringBuilder sql = new StringBuilder();
    sql.append("SELECT venda FROM Venda venda ");

    if (filtro.getDataInicial() != null & filtro.getDataFinal() != null) {
        sql.append("WHERE venda.horario BETWEEN :dataInicial AND :dataFinal ");
    }//  w  ww .  j a v  a2  s  .  c o m

    sql.append("ORDER BY venda.horario");

    Session sessao = HibernateUtil.getSessionFactory().openSession();
    try {
        Query consulta = sessao.createQuery(sql.toString());
        if (filtro.getDataInicial() != null & filtro.getDataFinal() != null) {
            consulta.setDate("dataInicial", filtro.getDataInicial());
            consulta.setDate("dataFinal", filtro.getDataFinal());
        }
        vendas = consulta.list();

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

From source file:br.com.ln.dao.TabelaDao.java

public static synchronized List<LnTabela> grabLnTabelaDate(Integer ttbInCodigo, Date tabDtInicio,
        Date tabDtFinal) {//from   w  w  w .  j a  v a2  s  . c  o m
    Session session = null;
    Transaction tx;
    List<LnTabela> listaTabela = null;

    try {
        session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName);
        tx = session.beginTransaction();

        Query query = session.createQuery(
                "select l from LnTabela l where l.ttbInCodigo = :ttbInCodigo and l.tabDtFinal >= :tabDtFinal");
        query.setInteger("ttbInCodigo", ttbInCodigo);
        query.setDate("tabDtFinal", tabDtFinal);
        listaTabela = query.list();
        tx.commit();

    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
    }

    return listaTabela;
}