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.aula.dao.LoginDAO.java

public String buscaSenha(String senha) {
    Session session = factory.openSession();
    String senhaDB = (String) session.createQuery("from Usuario where senha = " + senha).list().iterator()
            .next();/*from  www .ja v  a 2s  .c o  m*/
    session.flush();
    session.close();
    return senhaDB;
}

From source file:br.com.aula.dao.LoginDAO.java

public String buscaUsuario(String senha) {
    Session session = factory.openSession();

    String usuario = (String) session.createQuery("from Usuario where senha = " + senha).list().iterator()
            .next();/* w ww.  j a  va2  s .  co  m*/
    session.flush();
    session.close();
    return usuario;
}

From source file:br.com.aula.dao.LoginDAO.java

public boolean buscar(String login, String senha) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    //session.beginTransaction();
    String sql = " from Usuario u where u.usuario=:login and u.senha=:senha";
    Query query = session.createQuery(sql);
    query.setParameter("login", login);
    query.setParameter("senha", senha);
    List<Usuario> list = query.list();
    if (list.size() > 0) {
        session.close();//from  w ww . ja  va  2  s  .  com
        return true;
    }
    session.close();
    return false;
}

From source file:br.com.caelum.vraptor.util.migration.HibernateConnectionProvider.java

License:Open Source License

public List<String> getAppliedMigrations() {
    Session session = factory.openSession();
    try {/* w ww.j ava 2 s.  c o m*/
        return session.createQuery("select id from MigrationInfo").list();
    } finally {
        session.close();
    }
}

From source file:br.com.cary.dao.ProdutoEstoqueDAO.java

public void atualizarEstoque(ProdutoEstoque pe) {
    Session s = ConectaDB.getSessionFactory().openSession();
    try {//from  ww w .j  a v a  2  s.c  o  m
        s.beginTransaction();
        Query q = s.createQuery(
                "update ProdutoEstoque set quantidade = quantidade + :qtde where produto = :prod and setor = :setor")
                .setParameter("qtde", pe.getQuantidade()).setParameter("prod", pe.getProduto())
                .setParameter("setor", pe.getSetor());
        q.executeUpdate();
        s.getTransaction().commit();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        s.close();
    }
}

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

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

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

@Override
public List<DadosAdicionais> list() {
    Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
    ss.beginTransaction();//from   w ww  . ja  v  a 2 s  .c  om
    List lista = ss.createQuery("From dadosAdicionais ").list();
    ss.getTransaction().commit();
    return lista;
}

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

@Override
public List<Pessoa> list() {

    Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
    ss.beginTransaction();/*w  w  w.  ja  v a 2  s. co m*/
    List lista = ss.createQuery("From pessoa ").list();
    ss.getTransaction().commit();
    return lista;
}

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

public List<Pessoa> busca(String nome, String campo) {
    System.out.println("Entoru Busca");
    Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
    ss.beginTransaction();//w ww .j ava  2s . c  o m
    List lista = ss.createQuery("From pessoa p where p." + campo + " = '" + nome + "'").list();
    ss.getTransaction().commit();
    //ss.close();
    return lista;

}

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

@Override
public List<Prontuario> list() {
    Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
    ss.beginTransaction();//from   w  w w  . j  a  va2s .  co  m
    List lista = ss.createQuery("From prontuario ").list();
    ss.getTransaction().commit();
    return lista;
}