Example usage for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY

List of usage examples for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY

Introduction

In this page you can find the example usage for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY.

Prototype

ResultTransformer DISTINCT_ROOT_ENTITY

To view the source code for org.hibernate.criterion CriteriaSpecification DISTINCT_ROOT_ENTITY.

Click Source Link

Document

Each row of results is a distinct instance of the root entity

Usage

From source file:dao.hibernate.HibernateStudentDAO.java

@Override
public Student getStudentByPerson(Person person) throws EngineDAOException {
    getSession().beginTransaction();//www.  j a  v  a2 s  .  c o 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();/*from w  ww .  j  a v  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();//from w w w .ja  v  a2  s  .  co 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();/*from  w ww  .  j  a  v a2 s. co  m*/
    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();/* ww w .j  ava 2s .  c o 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();//w ww  .  j  a  v a2s . co  m
    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   w  w w .j a v  a 2  s .c om
    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();//  ww w  . j  a v a2  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 w w  w  . j  a va2  s.c o m
    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   ww w.  j a v  a2 s . c o  m*/
    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;
}