List of usage examples for org.hibernate Session createQuery
@Override org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);
From source file:br.com.apprestaurante.dao.CategoriaProdutoDao.java
public List<Produto> getAllByNome(String nome) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transacao = null;/*from w ww. jav a 2s . c om*/ List<Produto> lista = null; try { transacao = session.beginTransaction(); Query query = session.createQuery("from Produto as r where r.nome like :nome"); query.setParameter("nome", "%" + nome + "%"); lista = query.list(); transacao.commit(); return lista; } catch (HibernateException e) { if (transacao != null) { transacao.rollback(); } e.printStackTrace(); throw new HibernateException(e.getMessage()); } finally { session.close(); } }
From source file:br.com.arsmachina.authentication.dao.hibernate.UserDAOImpl.java
License:Apache License
/** * Finds the user with a given login and password. The login search is case-insensitive. * /* w w w. jav a 2s . c o m*/ * @see br.com.arsmachina.authentication.dao.UserDAO#findByLoginAndPassword(java.lang.String, * java.lang.String) */ public User findByLoginAndPassword(String login, String password) { Session session = getSession(); Query query = session .createQuery("from User where lowercase(login) = :login and " + "password = :password"); query.setParameter("login", login.toLowerCase()); query.setParameter("password", passwordEncrypter.encrypt(password)); return (User) query.uniqueResult(); }
From source file:br.com.arsmachina.authentication.dao.hibernate.UserDAOImpl.java
License:Apache License
/** * Finds an user by its login. The search is case-insensitive. * /*from w w w . ja v a2s.c om*/ * @see br.com.arsmachina.authentication.dao.UserDAO#findByLogin(java.lang.String) */ public User findByLogin(String login) { Session session = getSession(); Query query = session.createQuery("from User where lower(login) = :login"); query.setParameter("login", login.toLowerCase()); return (User) query.uniqueResult(); }
From source file:br.com.aula.dao.DepartamentoDAO.java
public List<Departamento> listarTodosDepartamentos() { Session session = factory.openSession(); List<Departamento> departamentos = session.createQuery("from Departamento").list(); session.flush();/* ww w. j a v a2 s. c om*/ session.close(); return departamentos; }
From source file:br.com.aula.dao.DepartamentoDAO.java
public Departamento consultarDepartamentoPorId(int idDepartamento) { Session session = factory.openSession(); Departamento departamento = (Departamento) session .createQuery("from Departamento where id=" + idDepartamento).list().iterator().next(); session.flush();/* w w w. ja va 2s . co m*/ session.close(); return departamento; }
From source file:br.com.aula.dao.DependenteDAO.java
public List<Dependente> listarTodosDependentes() { Session session = factory.openSession(); List<Dependente> dependentes = session.createQuery("from Dependente").list(); //session.flush(); //session.close(); return dependentes; }
From source file:br.com.aula.dao.DependenteDAO.java
public Dependente consultarDependentePorId(int idDependente) { Session session = factory.openSession(); Dependente dependente = (Dependente) session.createQuery("from Dependente where id=" + idDependente).list() .iterator().next();//from w w w . j a v a2s. c o m session.flush(); session.close(); return dependente; }
From source file:br.com.aula.dao.EmpresaDAO.java
public List<Empresa> listarTodosEmpresas() { Session session = factory.openSession(); List<Empresa> empresas = session.createQuery("from Empresa").list(); session.flush();/*from w ww .j a v a 2 s . c o m*/ session.close(); return empresas; }
From source file:br.com.aula.dao.EmpresaDAO.java
public Empresa consultarEmpresaPorId(int idEmpresa) { Session session = factory.openSession(); Empresa empresa = (Empresa) session.createQuery("from Empresa where id=" + idEmpresa).list().iterator() .next();//from w w w . j a va 2 s.co m session.flush(); session.close(); return empresa; }
From source file:br.com.aula.dao.LoginDAO.java
public boolean existe(Usuario usuario) { Session session = factory.openSession(); Query query = session.createQuery("from Usuario u where u.login = " + " :plogin and u.senha = :pSenha"); query.setParameter("plogin", usuario.getUsuario()); query.setParameter("pSenha", usuario.getSenha()); boolean encontrado = !query.list().isEmpty(); session.flush();/*from ww w . ja v a2 s . c om*/ session.close(); return encontrado; }