@SuppressWarnings("unchecked") @Override public List<Students> getStudentsFromGroup(Integer id) { Session session = null; List<Students> students = null; try { session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); // students = session.createCriteria(Students.class).add(Restrictions.eq("groups.groupid", // id)).list(); // students = session.createQuery ("select s from Students s").list(); students = session .createQuery("from Students s where s.groups.groupid = :var1 order by s.surname") .setParameter("var1", id) .list(); for (Students a : students) { Hibernate.initialize(a.getGroups()); Hibernate.initialize(a.getTypeEducation()); Hibernate.initialize(a.getGroups().getYearOfEducation().getNumberOfYear()); Hibernate.initialize(a.getUsers()); } session.getTransaction().commit(); } catch (Exception e) { log.info("Проблемы с сессией! " + e.getMessage()); } finally { if (session != null && session.isOpen()) { session.close(); } } return students; }
@SuppressWarnings("unchecked") public List<Students> getStudentsByDate(Date d) { Session session = null; List<Students> students = null; try { session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); students = session .createQuery("from Students s where s.datebirth = :var1") .setParameter("var1", d) .list(); for (Students a : students) { Hibernate.initialize(a.getGroups()); Hibernate.initialize(a.getTypeEducation()); Hibernate.initialize(a.getGroups().getYearOfEducation().getNumberOfYear()); } session.getTransaction().commit(); } catch (Exception e) { log.info("Проблемы с сессией! " + e.getMessage()); } finally { if (session != null && session.isOpen()) { session.close(); } } return students; }