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.HrmUserRoleDaoImpl.java

@Override
public List<HrmUserRole> getByUserId(long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("hrmUser", "su");
    criteria.add(Restrictions.eq("su.id", id));
    criteria.addOrder(Order.desc("hrmRole"));
    criteria.setFetchMode("hrmRole", FetchMode.JOIN);
    return criteria.list();
}

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

@Override
public List<Insurance> getByParam(InsuranceSearchParameter parameter, int firstResult, int maxResults,
        Order orderable) {//ww  w.  ja v a2s.com
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.setFetchMode("city", FetchMode.JOIN);
    criteria.setFetchMode("city.province", FetchMode.JOIN);
    criteria.setFetchMode("city.province.country", FetchMode.JOIN);
    doSearchByParam(parameter, criteria);
    criteria.addOrder(orderable);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

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

@Override
public Insurance getEntityByPkWithDetail(Long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.setFetchMode("city", FetchMode.JOIN);
    criteria.setFetchMode("city.province", FetchMode.JOIN);
    criteria.setFetchMode("city.province.country", FetchMode.JOIN);
    criteria.add(Restrictions.eq("id", id));
    return (Insurance) criteria.uniqueResult();
}

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

@Override
public Long getTotalJabatanByParam(JabatanSearchParameter searchParameter) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.setFetchMode("costCenter", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan", FetchMode.JOIN);
    criteria.setFetchMode("department", FetchMode.JOIN);
    criteria.setFetchMode("unitKerja", FetchMode.JOIN);
    criteria.setFetchMode("jabatan", FetchMode.JOIN);
    criteria.setFetchMode("paySalaryGrade", FetchMode.JOIN);

    criteria.createAlias("costCenter", "costCenter", JoinType.INNER_JOIN);
    criteria.createAlias("golonganJabatan", "golonganJabatan", JoinType.INNER_JOIN);
    criteria.createAlias("golonganJabatan.pangkat", "pangkat", JoinType.INNER_JOIN);
    criteria.createAlias("department", "department", JoinType.INNER_JOIN);
    criteria.createAlias("unitKerja", "unitKerja", JoinType.INNER_JOIN);
    criteria.createAlias("jabatan", "jabatan", JoinType.INNER_JOIN);
    criteria.createAlias("paySalaryGrade", "paySalaryGrade", JoinType.INNER_JOIN);

    doSearchByParam(searchParameter, criteria);
    return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
}

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

@Override
public List<Jabatan> getJabatanByParentCode(String parentCode) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    /** automatically get relations of department, company 
     *  don't create alias for that entity, or will get error : duplicate association path */
    criteria = this.addJoinRelationsOfCompanyId(criteria, HrmUserInfoUtil.getCompanyId());

    criteria.createAlias("jabatan", "jb", JoinType.INNER_JOIN);
    criteria.add(Restrictions.eq("jb.code", parentCode));
    criteria.setFetchMode("jabatans", FetchMode.JOIN);
    criteria.setFetchMode("jabatans.jabatan", FetchMode.JOIN);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    return criteria.list();
}

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

@Override
public Jabatan getJabatanByIdWithDetail(Long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("id", id));
    criteria.setFetchMode("costCenter", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan", FetchMode.JOIN);
    criteria.setFetchMode("department", FetchMode.JOIN);
    criteria.setFetchMode("department.company", FetchMode.JOIN);
    criteria.setFetchMode("unitKerja", FetchMode.JOIN);
    criteria.setFetchMode("jabatan", FetchMode.JOIN);
    return (Jabatan) criteria.uniqueResult();
}

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

@Override
public Jabatan getByIdWithJobDeskripsi(long id) throws Exception {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("id", id));
    criteria.setFetchMode("costCenter", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan", FetchMode.JOIN);
    criteria.setFetchMode("department", FetchMode.JOIN);
    criteria.setFetchMode("unitKerja", FetchMode.JOIN);
    criteria.setFetchMode("jabatan", FetchMode.JOIN);
    criteria.setFetchMode("jabatanDeskripsis", FetchMode.JOIN);
    criteria.setFetchMode("jabatanSpesifikasis", FetchMode.JOIN);
    criteria.setFetchMode("jabatanSpesifikasis.specificationAbility", FetchMode.JOIN);
    return (Jabatan) criteria.uniqueResult();
}

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

@Override
public Jabatan getByIdWithSalaryGrade(long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("id", id));
    criteria.setFetchMode("paySalaryGrade", FetchMode.JOIN);
    return (Jabatan) criteria.uniqueResult();
}

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

@Override
public List<Jabatan> getByName(String name) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    /** automatically get relations of department, company 
     *  don't create alias for that entity, or will get error : duplicate association path */
    criteria = this.addJoinRelationsOfCompanyId(criteria, HrmUserInfoUtil.getCompanyId());

    criteria.add(Restrictions.like("name", name, MatchMode.ANYWHERE));
    criteria.addOrder(Order.asc("name"));
    criteria.setFetchMode("department", FetchMode.JOIN);
    criteria.setFirstResult(0);/*  w  ww .  j ava  2 s  . c  o m*/
    criteria.setMaxResults(7);
    return criteria.list();
}

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

@Override
public Jabatan getJabatanByCode(String code) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("code", code));
    criteria.setFetchMode("costCenter", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan", FetchMode.JOIN);
    criteria.setFetchMode("department", FetchMode.JOIN);
    criteria.setFetchMode("department.company", FetchMode.JOIN);
    criteria.setFetchMode("unitKerja", FetchMode.JOIN);
    criteria.setFetchMode("jabatan", FetchMode.JOIN);
    return (Jabatan) criteria.uniqueResult();
}