List of usage examples for org.hibernate Criteria createAlias
@Deprecated public Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException;
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public Long getTotalByGender(Integer gender) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /**/*from ww w . j a va 2s .c o m*/ * automatically get relations of jabatanByJabatanId, 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.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); criteria.add(Restrictions.eq("bioData.gender", gender)); return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public Long getTotalByAgeBetween(Date startDate, Date endDate) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /**//w ww . j a v a 2s . c om * automatically get relations of jabatanByJabatanId, 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.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); criteria.add(Restrictions.gt("bioData.dateOfBirth", startDate)); criteria.add(Restrictions.lt("bioData.dateOfBirth", endDate)); return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public Long getTotalByAgeLessThan(Date date) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /**// ww w .j a va2 s .com * automatically get relations of jabatanByJabatanId, 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.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); criteria.add(Restrictions.lt("bioData.dateOfBirth", date)); return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public Long getTotalByAgeMoreThan(Date date) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /**// www. j a v a 2s. c o m * automatically get relations of jabatanByJabatanId, 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.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); criteria.add(Restrictions.gt("bioData.dateOfBirth", date)); return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }
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);// ww w. j a va 2 s. c o m 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
private void doSearchByParam(Long companyId, EmpDataSearchParameter dataSearchParameter, Criteria criteria) { /**// ww w .ja v a2 s .c o m * automatically get relations of jabatanByJabatanId, department, * company don't create alias for that entity, or will get error : * duplicate association path */ criteria = this.addJoinRelationsOfCompanyId(criteria, companyId); criteria.add(Restrictions.not(Restrictions.eq("status", HRMConstant.EMP_TERMINATION))); criteria.createAlias("wtGroupWorking", "wtGroupWorking", JoinType.INNER_JOIN); if (dataSearchParameter.getJabatanKode() != null) { criteria.add(Restrictions.like("jabatanByJabatanId.code", dataSearchParameter.getJabatanKode(), MatchMode.START)); } if (dataSearchParameter.getJabatanName() != null) { criteria.add(Restrictions.like("jabatanByJabatanId.name", dataSearchParameter.getJabatanName(), MatchMode.ANYWHERE)); } if (dataSearchParameter.getNIK() != null) { criteria.add(Restrictions.like("nik", dataSearchParameter.getNIK(), MatchMode.START)); } criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); if (dataSearchParameter.getName() != null) { // Disjunction disjunction = Restrictions.disjunction(); // disjunction.add(Restrictions.like("bioData.firstName", dataSearchParameter.getName(), MatchMode.START)); // disjunction.add(Restrictions.like("bioData.lastName", dataSearchParameter.getName(), MatchMode.START)); // criteria.add(disjunction); criteria.add(Restrictions.ilike("bioData.combineName", dataSearchParameter.getName().toLowerCase(), MatchMode.ANYWHERE)); } }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public List<EmpData> getAllDataByNameOrNik(String param, Long companyId) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /**/*from w w w .jav a2s. com*/ * automatically get relations of jabatanByJabatanId, department, * company don't create alias for that entity, or will get error : * duplicate association path */ criteria = this.addJoinRelationsOfCompanyId(criteria, companyId); //criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.add(Restrictions.isNotNull("status")); criteria.add(Restrictions .not(Restrictions.in("status", Arrays.asList(HRMConstant.EMP_TERMINATION, HRMConstant.EMP_DISCHAGED, HRMConstant.EMP_LAID_OFF, HRMConstant.EMP_STOP_CONTRACT, HRMConstant.EMP_PENSION)))); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.like("bioData.firstName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("bioData.lastName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("nik", param, MatchMode.ANYWHERE)); criteria.add(disjunction); criteria.setMaxResults(20); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public List<EmpData> getAllDataByNameOrNik(String param) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); //criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.add(Restrictions.isNotNull("status")); criteria.add(Restrictions//ww w . ja v a 2 s . c o m .not(Restrictions.in("status", Arrays.asList(HRMConstant.EMP_TERMINATION, HRMConstant.EMP_DISCHAGED, HRMConstant.EMP_LAID_OFF, HRMConstant.EMP_STOP_CONTRACT, HRMConstant.EMP_PENSION)))); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.like("bioData.firstName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("bioData.lastName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("nik", param, MatchMode.ANYWHERE)); criteria.add(disjunction); criteria.setMaxResults(20); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
private Criteria doSearchNotExistInUserByParam(String param, Criteria criteria) { /**/* ww w.j a v a2 s .c om*/ * automatically get relations of jabatanByJabatanId, 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.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN); if (param != null) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.like("bioData.firstName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("bioData.lastName", param, MatchMode.ANYWHERE)); disjunction.add(Restrictions.like("nik", param, MatchMode.ANYWHERE)); criteria.add(disjunction); } return criteria; }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public List<EmpData> getTotalBySearchEmployee(PlacementOfEmployeeWorkScheduleModel model) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /**/*w w w.j a v a 2s . com*/ * automatically get relations of jabatanByJabatanId, 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.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.createAlias("wtGroupWorking", "wg", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("employeeType", "empType", JoinType.INNER_JOIN); criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN); criteria.createAlias("golonganJabatan", "goljab", JoinType.INNER_JOIN); //ambil yg working groupnya bukan yg dipilih, dan belum punya working group if (model.getWorkingGroupId() != 0 || model.getWorkingGroupId() != null) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.isNull("wtGroupWorking")); disjunction.add(Restrictions.not(Restrictions.eq("wg.id", model.getWorkingGroupId()))); criteria.add(disjunction); } //departermen equal or like if (model.getDepartmentLikeOrEqual() != 3) { if (Objects.equals(model.getDepartmentLikeOrEqual(), HRMConstant.DEPARTMENT_EQUAL)) { criteria.add(Restrictions.eq("department.departmentName", model.getDepartmentName())); } else { criteria.add(Restrictions.like("department.departmentName", model.getDepartmentName(), MatchMode.ANYWHERE)); } } //employee type equal or like if (model.getEmployeeTypeLikeOrEqual() != 3) { if (Objects.equals(model.getEmployeeTypeLikeOrEqual(), HRMConstant.EMPLOYEE_TYPE_EQUAL)) { criteria.add(Restrictions.eq("empType.name", model.getEmployeeTypeName())); } else { criteria.add(Restrictions.like("empType.name", model.getEmployeeTypeName(), MatchMode.ANYWHERE)); } } //gender criteria.add(Restrictions.eq("bio.gender", model.getGender())); //goljab if (model.getGolonganJabatanId() != 0) { criteria.add(Restrictions.eq("goljab.id", model.getGolonganJabatanId())); } String sortBy; if (Objects.equals(model.getSortBy(), HRMConstant.SORT_BY_NIK)) { sortBy = "nik"; } else { sortBy = "bio.firstName"; } if (Objects.equals(model.getOrderBy(), HRMConstant.ORDER_BY_ASC)) { criteria.addOrder(Order.asc(sortBy)); } else { criteria.addOrder(Order.desc(sortBy)); } return criteria.list(); }