List of usage examples for org.hibernate Query setParameter
@SuppressWarnings("unchecked") Query<R> setParameter(int position, Object val);
From source file:br.vschettino.forum.dao.DiscussaoDAOImpl.java
@Override @Transactional// w w w . ja v a 2 s .com public Discussao getDiscussao(Long id) { List<Discussao> listDiscussao = new ArrayList<Discussao>(); Query query = sessionFactory.getCurrentSession().createQuery("from Discussao u where u.id = :id"); query.setParameter("id", id); listDiscussao = query.list(); if (listDiscussao.size() > 0) { return listDiscussao.get(0); } else { return null; } }
From source file:br.vschettino.forum.dao.RespostaDAOImpl.java
@Override @Transactional// w w w .j a v a 2 s.c o m public Resposta getResposta(Long id) { List<Resposta> listResposta = new ArrayList<Resposta>(); Query query = sessionFactory.getCurrentSession().createQuery("from Resposta u where u.id = :id"); query.setParameter("id", id); listResposta = query.list(); if (listResposta.size() > 0) { return listResposta.get(0); } else { return null; } }
From source file:br.vschettino.forum.dao.UsuarioDAOImpl.java
@Override @Transactional//from w w w . j a v a 2 s. c o m public Usuario getUsuario(String usuario) { List<Usuario> userList = new ArrayList<Usuario>(); Query query = sessionFactory.getCurrentSession().createQuery("from Usuario u where u.usuario = :usuario"); query.setParameter("usuario", usuario); userList = query.list(); if (userList.size() > 0) { return userList.get(0); } else { return null; } }
From source file:business.AccountDB.java
public static Account getAccount(String name) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;//from www. ja v a 2 s . c o m Account a = null; try { String qS = "FROM Account a WHERE a.name = :name"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("name", name); a = (Account) q.uniqueResult(); } catch (NoResultException e) { return null; } finally { if (session != null && session.isOpen()) { session.close(); } } return a; }
From source file:business.AccountDB.java
public static boolean checkAccountName(String name) { boolean used = false; SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;/*from w w w. j a v a 2 s.c o m*/ Account a; try { String qS = "FROM Account a WHERE a.name = :name"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("name", name); a = (Account) q.uniqueResult(); used = true; } catch (NoResultException e) { used = false; } finally { if (session != null && session.isOpen()) { session.close(); } } return used; }
From source file:business.ChampionDB.java
public static Champion getChampionByID(int cid) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;/*from w w w. j av a 2s . c om*/ Champion c = null; try { String qS = "FROM Champion c WHERE c.id = :cid"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("cid", cid); c = (Champion) q.uniqueResult(); } catch (HibernateException e) { c = null; } finally { if (session != null && session.isOpen()) { session.close(); } } return c; }
From source file:business.ChampionDB.java
public static List<Champion> loadChampions(int aid) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;//from w w w. ja v a 2 s . c om List<Champion> champs = null; try { String qS = "FROM Champion c WHERE c.accountID = :aid"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("aid", aid); champs = q.list(); } catch (HibernateException e) { champs = null; } finally { if (session != null && session.isOpen()) { session.close(); } } return champs; }
From source file:business.ChampionDB.java
public static boolean checkChampionName(String name) { boolean used = false; SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;/*from w w w . j av a 2 s.co m*/ Champion c; try { String qS = "FROM Champion c WHERE c.name = :name"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("name", name); c = (Champion) q.uniqueResult(); used = true; } catch (NoResultException e) { used = false; } finally { if (session != null && session.isOpen()) { session.close(); } } return used; }
From source file:business.OpponentDB.java
public static Opponent findOpponent(int oppID) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;//w w w. j a v a2 s . c om Opponent opp = null; try { String qS = "FROM Opponent o WHERE o.id = :oppID"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("oppID", oppID); opp = (Opponent) q.uniqueResult(); } catch (NoResultException e) { return null; } finally { if (session != null && session.isOpen()) { session.close(); } } return opp; }
From source file:business.PostDB.java
public static List<Post> loadPosts(int aid) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;/* w w w . ja v a 2 s . c o m*/ List<Post> posts = null; try { String qS = "FROM Post p WHERE p.accountID = :aid"; session = sessionFactory.openSession(); Query q = session.createQuery(qS); q.setParameter("aid", aid); posts = q.list(); } catch (HibernateException e) { posts = null; } finally { if (session != null && session.isOpen()) { session.close(); } } return posts; }