List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:dao.hibernate.HibernateStudentDAO.java
@Override public Student getStudentByPerson(Person person) throws EngineDAOException { getSession().beginTransaction();/*from w w w . ja va2s . co m*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(STUDENT_ID, person.getPersonID())); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Student student = null; try { student = (Student) criteria.uniqueResult(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (student == null) { throw new EngineDAOException(MessageFormat.format(ERROR_STUDENT_NOT_FOUND_BY_PERSON, null)); } return student; }
From source file:dao.hibernate.HibernateStudentDAO.java
@Override public Student getStudentByIndexNo(String indexNo) throws EngineDAOException { getSession().beginTransaction();/*w ww . j av a2 s .c o m*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(INDEX_NO, indexNo)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Student student = null; try { student = (Student) criteria.uniqueResult(); } catch (RuntimeException e) { getSession().getTransaction().commit(); throw new EngineDAOException(e); } if (student == null) { getSession().getTransaction().commit(); throw new EngineDAOException(MessageFormat.format(ERROR_STUDENT_NOT_FOUND_BY_PERSON, null)); } getSession().getTransaction().commit(); return student; }
From source file:dao.hibernate.HibernateStudentDAO.java
@Override public Student getStudentByIndexNoAndJMBG(String indexNo, String jmbg) throws EngineDAOException { getSession().beginTransaction();/* w w w . jav a 2s . c o m*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(INDEX_NO, indexNo)); criteria.add(Restrictions.eq(JMBG, jmbg)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Student student = null; try { student = (Student) criteria.uniqueResult(); } catch (RuntimeException e) { getSession().getTransaction().commit(); throw new EngineDAOException(e); } if (student == null) { getSession().getTransaction().commit(); throw new EngineDAOException(MessageFormat.format(ERROR_STUDENT_NOT_FOUND_BY_PERSON, null)); } getSession().getTransaction().commit(); return student; }
From source file:dao.hibernate.HibernateStudentDAO.java
@Override public Student getStudentByJMBG(String jmbg) throws EngineDAOException { getSession().beginTransaction();/*w ww .j a v a 2 s. c om*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(JMBG, jmbg)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); Student student = null; try { student = (Student) criteria.uniqueResult(); } catch (RuntimeException e) { getSession().getTransaction().commit(); throw new EngineDAOException(e); } if (student == null) { getSession().getTransaction().commit(); throw new EngineDAOException(MessageFormat.format(ERROR_STUDENT_NOT_FOUND_BY_PERSON, null)); } getSession().getTransaction().commit(); return student; }
From source file:dao.hibernate.HibernateSubjectDAO.java
@Override public List<Subject> getSubjectsByDepartments(Department department) throws EngineDAOException { getSession().beginTransaction();/*from w w w .j av a 2s. co m*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(DEPARTMENT, department)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Subject> subjects = null; try { subjects = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (subjects == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return subjects; }
From source file:dao.hibernate.HibernateWorkDAO.java
@Override public List<Work> getWorkByTitle(String title) throws EngineDAOException { getSession().beginTransaction();//from w ww .ja v a2s.c om Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(TITLE, title)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Work> works; try { works = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (works == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return works; }
From source file:dao.hibernate.HibernateWorkDAO.java
@Override public List<Work> getWorksByTitleAndSubject(String title, Subject subject) throws EngineDAOException { getSession().beginTransaction();//from ww w.j a va2 s . c o m Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(TITLE, title)); criteria.add(Restrictions.eq(SUBJECT, subject)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Work> works; try { works = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (works == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return works; }
From source file:dao.hibernate.HibernateWorkDAO.java
@Override public List<Work> getWorksBySubject(Subject subject) throws EngineDAOException { getSession().beginTransaction();//from ww w . jav a 2 s . c o m Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(SUBJECT, subject)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Work> works; try { works = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (works == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return works; }
From source file:dao.hibernate.HibernateWorkDAO.java
@Override public List<Work> getUnapprovedWorks() throws EngineDAOException { getSession().beginTransaction();/*from www. ja v a 2 s .com*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(STATUS, UNAPPROVED)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Work> works; try { works = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (works == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return works; }
From source file:dao.hibernate.HibernateWorkDAO.java
@Override public List<Work> getUncommisionedWorks() throws EngineDAOException { getSession().beginTransaction();/*from w ww .ja v a 2s. c om*/ Criteria criteria = getSession().createCriteria(persistentClass); criteria.add(Restrictions.eq(COMMISION, null)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Work> works; try { works = criteria.list(); } catch (RuntimeException e) { throw new EngineDAOException(e); } if (works == null) { getSession().getTransaction().rollback(); throw new EngineDAOException( MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null)); } getSession().getTransaction().commit(); return works; }