Exemple #1
0
 @SuppressWarnings("unchecked")
 public List<User> findAllUsers() throws PersistenceException {
   Session session = HibernateUtil.getSessionFactory().openSession();
   List<User> rs = null;
   try {
     session.beginTransaction();
     rs = session.createQuery("from " + User.class).list();
   } catch (Exception e) {
     throw new PersistenceException("Failed to find object", e);
   } finally {
     if (session.isOpen()) session.close();
   }
   return rs;
 }
Exemple #2
0
 @Override
 public User findUserByName(String name) throws PersistenceException {
   User user = null;
   String sql = "FROM User as u WHERE u.username = :name";
   Session session = HibernateUtil.getSessionFactory().openSession();
   try {
     session.beginTransaction();
     Query query = session.createQuery(sql).setParameter("name", name);
     user = findOne(query);
     // Hibernate.initialize(user.getDevices().size());
     // for(Device d : user.getDevices()){
     // Hibernate.initialize(d.getLogs().size());
     // Hibernate.initialize(d.getTracks().size());
     // }
   } catch (Exception e) {
     throw new PersistenceException("Failed to find object", e);
   } finally {
     session.close();
   }
   return user;
 }