Ejemplo n.º 1
0
 @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;
 }
Ejemplo n.º 2
0
 @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;
 }
Ejemplo n.º 3
0
  public void removeStudent(Integer idstudent) {
    Session session = null;
    try {
      session = HibernateUtil.getSessionFactory().openSession();
      session.beginTransaction();
      Students student = (Students) session.get(Students.class, idstudent);
      session.delete(student);
      session.getTransaction().commit();
      if (student != null) {

        System.out.println(student.toString());
      }
    } catch (Exception e) {
      log.info("Проблемы с сессией! " + e.getMessage());
    } finally {
      if (session != null && session.isOpen()) {
        session.close();
      }
    }
  }