List of usage examples for org.hibernate Query uniqueResult
R uniqueResult();
From source file:br.unisal.dao.PacienteDao.java
public Paciente getById(Paciente p) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Paciente paciente = new Paciente(); try {//w w w. j a va 2 s . c o m tx.begin(); Query query = session.createQuery("FROM Paciente WHERE idPaciente = :id"); query.setParameter("id", p.getIdPaciente()); paciente = (Paciente) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception PacienteDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return paciente; }
From source file:br.unisal.dao.ReuniaoDao.java
@Override public Reuniao getById(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Reuniao reuniao = new Reuniao(); try {//from w w w.j a v a 2 s. co m tx.begin(); Query query = session.createQuery("FROM Reuniao WHERE id_reuniao = :id"); query.setParameter("id", id); reuniao = (Reuniao) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception ReuniaoDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return reuniao; }
From source file:br.unisal.dao.SalaDao.java
@Override public Sala getById(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Sala sala = new Sala(); try {//from w w w . j a v a 2 s . com tx.begin(); Query query = session.createQuery("FROM Sala WHERE id_sala = :id"); query.setParameter("id", id); sala = (Sala) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception SalaDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return sala; }
From source file:br.unisal.dao.SensorDao.java
@Override public Sensor getById(Sensor s) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Sensor sensor = new Sensor(); try {/* w w w . j a v a 2s . co m*/ tx.begin(); Query query = session.createQuery("FROM Sensor WHERE idSensor = :id"); query.setParameter("id", s.getIdSensor()); sensor = (Sensor) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception SensorDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return sensor; }
From source file:br.unisal.dao.UsuarioDao.java
@Override public Usuario getById(Integer id) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Usuario usuario = new Usuario(); try {//from w w w . j a va 2s . co m tx.begin(); Query query = session.createQuery("FROM Usuario WHERE id_usuario = :id"); query.setParameter("id", id); usuario = (Usuario) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception UsuarioDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return usuario; }
From source file:br.unisal.twitter.dao.TweetDao.java
public Tweet getById(Tweet s) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Tweet sensor = new Tweet(); try {//from ww w .java2 s . c o m tx.begin(); Query query = session.createQuery("FROM Tweet WHERE id = :id"); query.setParameter("id", s.getId()); sensor = (Tweet) query.uniqueResult(); tx.commit(); } catch (HibernateException e) { System.out.println("Exception TweetDao.getById(): " + e.getMessage()); tx.rollback(); } finally { session.close(); } return sensor; }
From source file:business.AccountDB.java
public static Account getAccount(String name) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;//from w ww. j a v a 2s.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;// w w w . j a va2 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 ava2s.c o m 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 boolean checkChampionName(String name) { boolean used = false; SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = null;/* ww w. j a v a2 s .com*/ 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; }