Example usage for org.hibernate Criteria createAlias

List of usage examples for org.hibernate Criteria createAlias

Introduction

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

Prototype

@Deprecated
public Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException;

Source Link

Document

Join an association using the specified join-type, assigning an alias to the joined association.

Usage

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

public void doSearchByParam(BioPotensiSwotSearchParameter searchParameter, Criteria criteria) {
    if (searchParameter.getName() != null) {
        criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN);
        Disjunction disjunction = Restrictions.disjunction();
        disjunction.add(Restrictions.like("bio.firstName", searchParameter.getName(), MatchMode.START));
        disjunction.add(Restrictions.like("bio.lastName", searchParameter.getName(), MatchMode.START));
        criteria.add(disjunction);//w w w. j  ava  2s.  c om
    }
    criteria.add(Restrictions.isNotNull("id"));
}

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

public void doSearchByParam(BioRelasiPerusahaanSearchParameter searchParameter, Criteria criteria) {
    if (searchParameter.getName() != null) {
        criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN);
        Disjunction disjunction = Restrictions.disjunction();
        disjunction.add(Restrictions.like("bio.firstName", searchParameter.getName(), MatchMode.START));
        disjunction.add(Restrictions.like("bio.lastName", searchParameter.getName(), MatchMode.START));
        criteria.add(disjunction);//from  w w w  .j  a v  a2 s  . c o m
    }
    criteria.add(Restrictions.isNotNull("id"));
}

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

private void doSearchTerminationTypeByParam(CareerTerminationTypeSearchParameter searchParameter,
        Criteria criteria) {
    criteria.createAlias("systemLetterReference", "systemLetterReference", JoinType.INNER_JOIN);
    criteria.createAlias("systemCareerConst", "systemCareerConst", JoinType.INNER_JOIN);
    if (StringUtils.isNotBlank(searchParameter.getCode())) {
        criteria.add(Restrictions.like("code", searchParameter.getCode(), MatchMode.ANYWHERE));
    }/*from ww w.  j  a v a2  s.  c  o  m*/

    if (StringUtils.isNotBlank(searchParameter.getName())) {
        criteria.add(Restrictions.like("name", searchParameter.getName(), MatchMode.ANYWHERE));
    }
    criteria.add(Restrictions.isNotNull("id"));
}

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

@Override
public List<CompanyCommisioner> getEntityByCompanyId(Long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("company", "company", JoinType.LEFT_OUTER_JOIN);
    criteria.add(Restrictions.eq("company.id", id));
    return criteria.list();
}

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

@Override
public List<Divisi> getByParam(DivisiSearchParameter searchParameter, int firstResult, int maxResults,
        Order order) {/*from   ww w  .  j  a va2 s  .  co  m*/
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchByParam(searchParameter, criteria);
    criteria.addOrder(order);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    //criteria.setFetchMode("department", FetchMode.JOIN);
    criteria.createAlias("department", "department", JoinType.INNER_JOIN);
    return criteria.list();
}

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 EmpCareerHistory getByBioIdandStatus(long id, String status) {
    DetachedCriteria maxEvaluationScore = DetachedCriteria.forClass(getEntityClass())
            .setProjection(Property.forName("createdOn").max())
            .createAlias("bioData", "bio", JoinType.INNER_JOIN).add(Restrictions.eq("bio.id", id))
            .add(Restrictions.eq("status", status));

    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN);
    criteria.add(Restrictions.eq("bio.id", id));
    criteria.add(Restrictions.eq("status", status));
    criteria.add(Property.forName("createdOn").eq(maxEvaluationScore));
    return (EmpCareerHistory) criteria.uniqueResult();
}

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);//from   w w  w. j  av a 2  s  .  c o  m
    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 List<EmpCareerHistory> getPreviousEmpCareerByBioDataIdAndCurrentCreatedOn(Long bioDataId,
        Date currentCreatedOn) {//w w  w . ja  va2s.  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

private Criteria addJoinRelationsOfCompanyId(Criteria criteria, Long companyId) {
    criteria.createAlias("jabatanByJabatanId", "jabatanByJabatanId", JoinType.INNER_JOIN);
    criteria.createAlias("jabatanByJabatanId.department", "department", JoinType.INNER_JOIN);
    criteria.createAlias("department.company", "company", JoinType.INNER_JOIN);
    criteria.add(Restrictions.eq("company.id", companyId));

    return criteria;
}