Example usage for org.hibernate Criteria setFetchMode

List of usage examples for org.hibernate Criteria setFetchMode

Introduction

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

Prototype

public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException;

Source Link

Document

Specify an association fetching strategy for an association or a collection of values.

Usage

From source file:com.inkubator.hrm.dao.impl.CareerTerminationTypeDaoImpl.java

@Override
public CareerTerminationType getEntityWithDetailById(Long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("id", id));
    criteria.setFetchMode("systemLetterReference", FetchMode.JOIN);
    criteria.setFetchMode("systemCareerConst", FetchMode.JOIN);
    return (CareerTerminationType) criteria.uniqueResult();
}

From source file:com.inkubator.hrm.dao.impl.DepartementUnitLocationDaoImpl.java

@Override
public List<DepartementUnitLocation> getByDepartementId(long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("department", "dp");
    criteria.add(Restrictions.eq("dp.id", id));
    criteria.addOrder(Order.desc("unitKerja"));
    criteria.setFetchMode("unitKerja", FetchMode.JOIN);
    return criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.DepartementUploadCaptureDaoImpl.java

@Override
public List<DepartementUploadCapture> getByMecineFingerId(long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("mecineFinger", "d");
    criteria.add(Restrictions.eq("d.id", id));
    criteria.addOrder(Order.asc("department"));
    criteria.setFetchMode("department", FetchMode.JOIN);
    return criteria.list();

}

From source file:com.inkubator.hrm.dao.impl.DivisiDaoImpl.java

@Override
public Divisi getDepartmentNameByDivisiId(Long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("id", id));
    criteria.setFetchMode("department", FetchMode.JOIN);
    return (Divisi) criteria.uniqueResult();
}

From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java

@Override
public List<EmpCareerHistory> getEmployeeCareerByBioId(long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN);
    criteria.add(Restrictions.eq("bio.id", id));
    criteria.setFetchMode("jabatan", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan.pangkat", FetchMode.JOIN);
    criteria.setFetchMode("employeeType", FetchMode.JOIN);
    criteria.addOrder(Order.asc("tglPenganngkatan"));
    return criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java

@Override
public List<EmpCareerHistory> getByParamReport(ReportEmpMutationParameter searchParameter, int firstResult,
        int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    criteria.createAlias("jabatan", "jabatan", JoinType.INNER_JOIN);
    doSearchEmpRotasiByParamReport(searchParameter, criteria);

    DetachedCriteria maxTglPengangkatanQuery = DetachedCriteria.forClass(getEntityClass());
    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.max("tglPenganngkatan"));
    proj.add(Projections.groupProperty("nik"));
    maxTglPengangkatanQuery.setProjection(proj);

    criteria.add(Subqueries.propertiesIn(new String[] { "tglPenganngkatan", "nik" }, maxTglPengangkatanQuery));
    criteria.addOrder(order);/*ww  w.  ja va  2s .  c om*/
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);

    List<EmpCareerHistory> listEmpCareerHistorys = criteria.list();

    //Set Jabatan Lama/sebelumnya dari masing - masing record
    for (EmpCareerHistory ech : listEmpCareerHistorys) {
        Criteria criteriaOldPosition = getCurrentSession().createCriteria(getEntityClass());
        criteriaOldPosition.setFetchMode("jabatan", FetchMode.JOIN);
        criteriaOldPosition.add(Restrictions.eq("nik", ech.getNik()));
        criteriaOldPosition.add(Restrictions.lt("tglPenganngkatan", ech.getTglPenganngkatan()));
        criteriaOldPosition.addOrder(Order.desc("tglPenganngkatan"));
        criteriaOldPosition.setMaxResults(1);
        EmpCareerHistory prevPosition = (EmpCareerHistory) criteriaOldPosition.uniqueResult();

        //jika sebelumnya dia sudah pernah menjabat di posisi lain maka set oldJabatan dengan posisi tersebut
        if (null != prevPosition) {
            ech.setJabatanOldCode(prevPosition.getJabatan().getCode());
            ech.setJabatanOldName(prevPosition.getJabatan().getName());
        } else {
            ech.setJabatanOldCode("-");
        }
    }

    return listEmpCareerHistorys;
}

From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java

@Override
public EmpCareerHistory getEntityByApprovalActivityNumber(String approvalActivityNumber) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("approvalActivityNumber", approvalActivityNumber));
    criteria.setFetchMode("bioData", FetchMode.JOIN);
    criteria.setFetchMode("copyOfLetterTo", FetchMode.JOIN);
    criteria.setFetchMode("copyOfLetterTo.bioData", FetchMode.JOIN);
    criteria.setFetchMode("employeeType", FetchMode.JOIN);
    criteria.setFetchMode("jabatan", FetchMode.JOIN);
    criteria.setFetchMode("jabatan.department", FetchMode.JOIN);
    criteria.setFetchMode("jabatan.department.company", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan.pangkat", FetchMode.JOIN);
    criteria.setFetchMode("careerTransition", FetchMode.JOIN);
    return (EmpCareerHistory) criteria.uniqueResult();
}

From source file:com.inkubator.hrm.dao.impl.EmpCareerHistoryDaoImpl.java

@Override
public List<EmpCareerHistory> getPreviousEmpCareerByBioDataIdAndCurrentCreatedOn(Long bioDataId,
        Date currentCreatedOn) {/*from   w w  w .  j av  a 2 s. c  o  m*/
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    criteria.add(Restrictions.eq("bioData.id", bioDataId));
    criteria.add(Restrictions.lt("createdOn", currentCreatedOn));
    criteria.addOrder(Order.desc("createdOn"));
    criteria.setFetchMode("copyOfLetterTo", FetchMode.JOIN);
    criteria.setFetchMode("copyOfLetterTo.bioData", FetchMode.JOIN);
    criteria.setFetchMode("employeeType", FetchMode.JOIN);
    criteria.setFetchMode("jabatan", FetchMode.JOIN);
    criteria.setFetchMode("jabatan.department", FetchMode.JOIN);
    criteria.setFetchMode("jabatan.department.company", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan.pangkat", FetchMode.JOIN);
    /*criteria.setMaxResults(1);*/
    return criteria.list();

}

From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java

@Override
public List<EmpData> getAllDataByParam(Long companyId, EmpDataSearchParameter searchParameter, int firstResult,
        int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchByParam(companyId, searchParameter, criteria);
    criteria.addOrder(order);//from w w  w  .  ja va  2s  . c om
    criteria.createAlias("golonganJabatan", "golonganJabatan", JoinType.LEFT_OUTER_JOIN);
    //        criteria.createAlias("bioData", "bioData", JoinType.LEFT_OUTER_JOIN);

    //        criteria.createAlias("jabatanByJabatanId", "bioData", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("taxFree", "taxFree", JoinType.INNER_JOIN);
    //        criteria.setFetchMode("bioData", FetchMode.JOIN);
    criteria.setFetchMode("bioData.city", FetchMode.JOIN);
    criteria.setFetchMode("bioData.maritalStatus", FetchMode.JOIN);
    //        criteria.setFetchMode("jabatanByJabatanId", FetchMode.JOIN);
    //        criteria.setFetchMode("golonganJabatan", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan.pangkat", FetchMode.JOIN);
    criteria.setFetchMode("jabatanByJabatanId.department", FetchMode.JOIN);
    criteria.setFetchMode("jabatanByJabatanId.unitKerja", FetchMode.JOIN);
    criteria.setFetchMode("wtGroupWorking", FetchMode.JOIN);
    //        criteria.setFetchMode("taxFree", FetchMode.JOIN);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java

@Override
public EmpData getByEmpIdWithDetail(long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("id", id));
    criteria.setFetchMode("jabatanByJabatanId", FetchMode.JOIN);
    criteria.setFetchMode("jabatanByJabatanId.department", FetchMode.JOIN);
    criteria.setFetchMode("jabatanByJabatanId.department.company", FetchMode.JOIN);
    criteria.setFetchMode("jabatanByJabatanId.jabatan", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan", FetchMode.JOIN);
    criteria.setFetchMode("bioData", FetchMode.JOIN);
    criteria.setFetchMode("employeeType", FetchMode.JOIN);
    criteria.setFetchMode("paySalaryGrade", FetchMode.JOIN);
    criteria.setFetchMode("jabatanByJabatanId.jabatanDeskripsis", FetchMode.JOIN);
    criteria.setFetchMode("jabatanByJabatanId.jabatanSpesifikasis", FetchMode.JOIN);
    criteria.setFetchMode("jabatanByJabatanId.jabatanSpesifikasis.specificationAbility", FetchMode.JOIN);
    criteria.setFetchMode("wtGroupWorking", FetchMode.JOIN);
    return (EmpData) criteria.uniqueResult();
}