Example usage for org.hibernate Criteria setResultTransformer

List of usage examples for org.hibernate Criteria setResultTransformer

Introduction

In this page you can find the example usage for org.hibernate Criteria setResultTransformer.

Prototype

public Criteria setResultTransformer(ResultTransformer resultTransformer);

Source Link

Document

Set a strategy for handling the query results.

Usage

From source file:dao.DiskDao.java

/**
 * ?,   /*w  w  w .  j  ava2  s  . c  o  m*/
 * @param user
 * @return 
 */
public List<Disk> getDisksByOwner(User user) {
    Criteria crit = getCurrentSession().createCriteria(Disk.class);
    crit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    crit.add(Restrictions.eq("user.userId", user.getUserId()));
    return crit.list();
}

From source file:dao.EncargadoDaoImpl.java

@Override
public List<Encargado> findAll() {
    Criteria criteria = createEntityCriteria();
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates.
    List<Encargado> encargado = (List<Encargado>) criteria.list();

    return encargado;
}

From source file:dao.EnfermedadDaoImpl.java

@Override
public List<Enfermedad> findAll() {
    Criteria criteria = createEntityCriteria();
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates.
    List<Enfermedad> matricula = (List<Enfermedad>) criteria.list();

    return matricula;
}

From source file:dao.EspecialidadDaoImpl.java

@Override
public List<Especialidad> findAll() {
    Criteria criteria = createEntityCriteria();
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates.
    List<Especialidad> clase = (List<Especialidad>) criteria.list();

    return clase;
}

From source file:dao.FacturaDaoImpl.java

@Override
public List<Factura> findAll() {
    Criteria criteria = createEntityCriteria();
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates.
    List<Factura> factura = (List<Factura>) criteria.list();

    return factura;
}

From source file:dao.FamiliarDaoImpl.java

@Override
public List<Familiar> findAll() {
    Criteria criteria = createEntityCriteria();
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);//To avoid duplicates.
    List<Familiar> familiar = (List<Familiar>) criteria.list();

    return familiar;
}

From source file:dao.hibernate.HibernateCommunicationDAO.java

@Override
public List<Communication> getCommunicationsByEmployee(Employee employee) throws EngineDAOException {
    getSession().beginTransaction();//from  w  ww  . jav  a 2 s  .  c  o  m
    Criteria criteria = getSession().createCriteria(persistentClass);
    criteria.add(Restrictions.eq(EMPLOYEE, employee));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List<Communication> cs = null;
    try {
        cs = criteria.list();
    } catch (RuntimeException e) {
        throw new EngineDAOException(e);
    }
    if (cs == null) {
        getSession().getTransaction().rollback();
        throw new EngineDAOException(
                MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null));
    }
    getSession().getTransaction().commit();
    return cs;
}

From source file:dao.hibernate.HibernateCommunicationDAO.java

@Override
public List<Communication> getCommunicationsByStudent(Student student) throws EngineDAOException {
    getSession().beginTransaction();/*  w  w w  .ja  v a  2s.c  o  m*/
    Criteria criteria = getSession().createCriteria(persistentClass);
    criteria.add(Restrictions.eq(STUDENT, student));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List<Communication> cs = null;
    try {
        cs = criteria.list();
    } catch (RuntimeException e) {
        throw new EngineDAOException(e);
    }
    if (cs == null) {
        getSession().getTransaction().rollback();
        throw new EngineDAOException(
                MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null));
    }
    getSession().getTransaction().commit();
    return cs;
}

From source file:dao.hibernate.HibernateCommunicationDAO.java

@Override
public Communication getCommunicationByEmployeeAndStudent(Employee employee, Student student)
        throws EngineDAOException {
    getSession().beginTransaction();/*from w ww.  jav a2 s .c  o m*/
    Criteria criteria = getSession().createCriteria(persistentClass);
    criteria.add(Restrictions.eq(STUDENT, student));
    criteria.add(Restrictions.eq(EMPLOYEE, employee));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    Communication communication = null;
    try {
        communication = (Communication) criteria.uniqueResult();
    } catch (RuntimeException e) {
        throw new EngineDAOException(e);
    }
    if (communication == null) {
        getSession().getTransaction().rollback();
        throw new EngineDAOException(
                MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null));
    }
    getSession().getTransaction().commit();
    return communication;
}

From source file:dao.hibernate.HibernateEmployeeDAO.java

@Override
public List<Employee> getEmployeesByName(String name) throws EngineDAOException {
    getSession().beginTransaction();//from  w w w . jav  a2 s. co  m
    Criteria criteria = getSession().createCriteria(persistentClass);
    criteria.add(Restrictions.eq(HibernatePersonDAO.NAME, name));
    //criteria.add(Restrictions.eq(PASSWORD, password));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List<Employee> employees = null;
    try {
        employees = criteria.list();
    } catch (RuntimeException e) {
        throw new EngineDAOException(e);
    }
    if (employees == null) {
        getSession().getTransaction().rollback();
        throw new EngineDAOException(
                MessageFormat.format(ERROR_PERSON_NOT_FOUND_BY_USERNAME_AND_PASSWORD, null));
    }
    getSession().getTransaction().commit();
    return employees;
}