Java Code Examples for org.hibernate.criterion.DetachedCriteria#add()

The following examples show how to use org.hibernate.criterion.DetachedCriteria#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProductService.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Odata dedicated Services
 */
@Transactional(readOnly = true)
@Cacheable (value = "product_count", key = "{#criteria, #uuid}")
public int countProducts (DetachedCriteria criteria, String uuid)
{
   if (criteria == null)
   {
      criteria = DetachedCriteria.forClass (Product.class);
   }

   // count only processed products
   criteria.add (Restrictions.eq ("processed", true));

   if (uuid != null)
   {
      List<Long> product_ids = collectionService.getProductIds (uuid);
      criteria.add (Restrictions.in ("id", product_ids));
   }
   criteria.setProjection (Projections.rowCount ());
   return productDao.count (criteria);
}
 
Example 2
Source File: MassMailDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
protected long handleGetCount(Long trialId, Long probandListStatusTypeId, Boolean locked, Long resendProbandId) throws Exception {
	org.hibernate.Criteria massMailCriteria = createMassMailCriteria("massMail0");
	if (trialId != null) {
		massMailCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
	}
	if (probandListStatusTypeId != null) {
		massMailCriteria.add(Restrictions.eq("probandListStatus.id", probandListStatusTypeId.longValue()));
	}
	if (locked != null) {
		massMailCriteria.createCriteria("status").add(Restrictions.eq("locked", locked.booleanValue()));
	}
	if (resendProbandId != null) {
		DetachedCriteria recipientsSubQuery = DetachedCriteria.forClass(MassMailRecipientImpl.class, "massMailRecipient1"); // IMPL!!!!
		recipientsSubQuery.setProjection(Projections.rowCount());
		recipientsSubQuery.add(Restrictions.eq("proband.id", resendProbandId.longValue()));
		recipientsSubQuery.add(Restrictions.eqProperty("massMail.id", "massMail0.id"));
		massMailCriteria.add(Restrictions.or(Restrictions.eq("probandListStatusResend", true),
				Subqueries.eq(0l, recipientsSubQuery)));
	}
	return (Long) massMailCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
 
Example 3
Source File: ECRFFieldValueDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 6 votes vote down vote up
private org.hibernate.Criteria[] createEcrfFieldCriteria(Long probandListEntryId, Long ecrfId) {
	org.hibernate.Criteria ecrfFieldCriteria = this.getSession().createCriteria(ECRFField.class, ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_ALIAS);
	ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));
	org.hibernate.Criteria ecrfFieldValueCriteria = ecrfFieldCriteria.createCriteria("fieldValues", ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_VALUE_ALIAS,
			CriteriaSpecification.LEFT_JOIN,
			Restrictions.eq(ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_VALUE_ALIAS + ".listEntry.id", probandListEntryId.longValue()));
	// correlated - slow:
	DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteriaMaxId(ecrfFieldValueCriteria, ecrfFieldCriteria, null, probandListEntryId, null);
	subQuery.add(Restrictions.or(Restrictions.isNull("index"),
			Restrictions.eqProperty("index", ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_VALUE_ALIAS + ".index")));
	ecrfFieldValueCriteria.add(Restrictions.or(
			Restrictions.isNull("listEntry"),
			Restrictions.and(
					Restrictions.eq("listEntry.id", probandListEntryId.longValue()),
					Subqueries.propertyIn("id", subQuery))));
	return new org.hibernate.Criteria[] { ecrfFieldCriteria, ecrfFieldValueCriteria };
}
 
Example 4
Source File: UploadVideoController.java    From TinyMooc with Apache License 2.0 6 votes vote down vote up
@RequestMapping("goShowVideo.htm")
public ModelAndView goShowVideo(HttpServletRequest request) {
    String courseId = "1";
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Resource.class);
    detachedCriteria.add(Restrictions.eq("resourceObject", courseId));
    detachedCriteria.add(Restrictions.eq("type", "video"));

    List<Resource> resourceList = uploadService.queryMaxNumOfCondition(Resource.class, detachedCriteria, 1);
    Resource resource = resourceList.get(0);
    DetachedCriteria dCriteria = DetachedCriteria.forClass(Video.class);
    dCriteria.add(Restrictions.eq("resourceId", resource.getResourceId()));
    List<Video> videoList = uploadService.queryAllOfCondition(Video.class, dCriteria);

    Video video = videoList.get(0);
    request.setAttribute("video", video);

    return new ModelAndView("/help/showVideo");
}
 
Example 5
Source File: ProbandListEntryDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected Collection<ProbandListEntry> handleGetProbandList(
		Long trialId, org.phoenixctms.ctsms.enumeration.ProbandListStatusLogLevel logLevel, boolean last)
		throws Exception {
	// http://stackoverflow.com/questions/1648426/hibernate-detached-queries-as-a-part-of-the-criteria-query
	// https://forum.hibernate.org/viewtopic.php?p=2317841#2317841
	org.hibernate.Criteria listEntryCriteria = createListEntryCriteria();
	boolean distinctRoot = false;
	if (trialId != null) {
		listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
	}
	if (logLevel != null) {
		org.hibernate.Criteria statusEntryCriteria;
		if (last) {
			statusEntryCriteria = listEntryCriteria.createCriteria("statusEntries", "probandListStatusEntry0", CriteriaSpecification.INNER_JOIN);
		} else {
			statusEntryCriteria = listEntryCriteria.createCriteria("statusEntries", CriteriaSpecification.INNER_JOIN);
		}
		org.hibernate.Criteria statusTypeCriteria = statusEntryCriteria.createCriteria("status", CriteriaSpecification.INNER_JOIN);
		org.hibernate.Criteria logLevelCriteria = statusTypeCriteria.createCriteria("logLevels", CriteriaSpecification.INNER_JOIN);
		logLevelCriteria.add(Restrictions.eq("logLevel", logLevel));
		if (last) {
			DetachedCriteria subQuery = DetachedCriteria.forClass(ProbandListStatusEntryImpl.class, "probandListStatusEntry1"); // IMPL!!!!
			subQuery.add(Restrictions.eqProperty("probandListStatusEntry1.listEntry", "probandListStatusEntry0.listEntry"));
			subQuery.setProjection(Projections.max("id"));
			statusEntryCriteria.add(Subqueries.propertyEq("id", subQuery));
		} else {
			distinctRoot = true;
		}
	}
	listEntryCriteria.addOrder(Order.asc("trial"));
	listEntryCriteria.addOrder(Order.asc("position"));
	if (distinctRoot) {
		return CriteriaUtil.listDistinctRoot(listEntryCriteria, this, "trial.id", "position");
	} else {
		return listEntryCriteria.list();
	}
}
 
Example 6
Source File: GoodsCatDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public GoodsCat findById(int id) {
    DetachedCriteria criteria = DetachedCriteria.forClass(GoodsCat.class);
    criteria.add(Restrictions.eq("id", id));
    List<GoodsCat> resultList = (List<GoodsCat>) template.findByCriteria(criteria);
    if (resultList.size() == 0) {
        return null;
    }
    return resultList.get(0);
}
 
Example 7
Source File: DepartController.java    From jeecg with Apache License 2.0 5 votes vote down vote up
/**
	 * 方法描述:  成员列表dataGrid
	 * 作    者: yiming.zhang
	 * 日    期: Dec 4, 2013-10:40:17 PM
	 * @param user
	 * @param request
	 * @param response
	 * @param dataGrid 
	 * 返回类型: void
	 */
	@RequestMapping(params = "userDatagrid")
	public void userDatagrid(TSUser user,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		if(user!=null&&user.getDepartid()!=null){
			user.setDepartid(null);//设置用户的所属部门的查询条件为空;
		}
		CriteriaQuery cq = new CriteriaQuery(TSUser.class, dataGrid);
		//查询条件组装器
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, user);
		String departid = oConvertUtils.getString(request.getParameter("departid"));
		if (!StringUtil.isEmpty(departid)) {
			DetachedCriteria dc = cq.getDetachedCriteria();
			DetachedCriteria dcDepart = dc.createCriteria("userOrgList");
			dcDepart.add(Restrictions.eq("tsDepart.id", departid));
            // 这种方式也是可以的
//            DetachedCriteria dcDepart = dc.createAlias("userOrgList", "userOrg");
//            dcDepart.add(Restrictions.eq("userOrg.tsDepart.id", departid));

		}
		Short[] userstate = new Short[] { Globals.User_Normal, Globals.User_ADMIN };
		cq.in("status", userstate);

        //cq.eq("deleteFlag", Globals.Delete_Normal);//删除状态,不删除
        //cq.eq("userType",Globals.USER_TYPE_SYSTEM);//系统用户

		cq.add();
		this.systemService.getDataGridReturn(cq, true);
		TagUtil.datagrid(response, dataGrid);
	}
 
Example 8
Source File: NoteController.java    From TinyMooc with Apache License 2.0 5 votes vote down vote up
@RequestMapping("gocourseNote.htm")
public ModelAndView gocourseNote(HttpServletRequest request) {
    String courseId = request.getParameter("courseId");
    User user = (User) request.getSession().getAttribute("user");
    Course course = noteService.findById(Course.class, courseId);

    DetachedCriteria dCriteria3 = DetachedCriteria.forClass(UserCourse.class);
    dCriteria3.add(Restrictions.eq("course", course));
    dCriteria3.add(Restrictions.eq("user", user));
    List<UserCourse> courseList1 = noteService.queryAllOfCondition(UserCourse.class, dCriteria3);
    DetachedCriteria dCriteria = DetachedCriteria.forClass(UserCourse.class);
    dCriteria.add(Restrictions.eq("course", course));
    List<UserCourse> courseList = noteService.queryAllOfCondition(UserCourse.class, dCriteria);

    int userNum = courseList.size();
    int noteSum = 0;
    for (int i = 0; i < courseList.size(); i++) {
        UserCourse userCourse = courseList.get(i);
        DetachedCriteria dCriteria2 = DetachedCriteria.forClass(Note.class);
        dCriteria2.add(Restrictions.eq("userCourse", userCourse));
        List<Note> noteList = noteService.queryAllOfCondition(Note.class, dCriteria2);
        int noteNum1 = noteList.size();
        noteSum = noteSum + noteNum1;
    }
    int credit = user.getCredit();
    Level level = userService.getUserLevel(credit);
    request.setAttribute("level", level);
    request.setAttribute("course", course);
    request.setAttribute("userNum", userNum);
    request.setAttribute("noteSum", noteSum);
    request.setAttribute("courseList1", courseList1);
    return new ModelAndView("/note/courseNote", "courseList", courseList);
}
 
Example 9
Source File: ShoppingCartDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
@Transactional
public void delShoppingCart(int[] cart) {
    DetachedCriteria criteria=DetachedCriteria.forClass(ShoppingCart.class);
    Disjunction dis = Restrictions.disjunction();
    for(int item : cart) {
        System.out.println(item);
        dis.add(Restrictions.eq("id", item));
    }
    criteria.add(dis);
    List<ShoppingCart> list = (List<ShoppingCart>) template.findByCriteria(criteria);
    template.deleteAll(list);
}
 
Example 10
Source File: GoodsCommentDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public List<GoodsComment> findByGoodsId(int goodsId) {
    DetachedCriteria criteria = DetachedCriteria.forClass(GoodsComment.class);

    criteria.add(Restrictions.eq("goodsid", goodsId));
    return (List<GoodsComment>) template.findByCriteria(criteria);
}
 
Example 11
Source File: ECRFFieldValueDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void applyEcrfFieldValueMaxIdSubCriteria(org.hibernate.Criteria ecrfFieldValueCriteria, org.hibernate.Criteria ecrfFieldCriteria,
		org.hibernate.Criteria probandListEntryCriteria, Long probandListEntryId, Long ecrfFieldId) {
	DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteriaMaxId(ecrfFieldValueCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId, ecrfFieldId);
	subQuery.add(Restrictions.or(Restrictions.isNull("index"),
			Restrictions.eqProperty("index", ecrfFieldValueCriteria.getAlias() + ".index")));
	ecrfFieldValueCriteria.add(Subqueries.propertyEq("id", subQuery));
}
 
Example 12
Source File: ECRFFieldValueDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void applyEcrfFieldValueMaxIdSubCriteria(org.hibernate.Criteria ecrfFieldValueCriteria, org.hibernate.Criteria ecrfFieldCriteria,
		org.hibernate.Criteria probandListEntryCriteria, Long probandListEntryId, Long ecrfFieldId, Long index) {
	DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteriaMaxId(ecrfFieldValueCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId, ecrfFieldId);
	if (index != null) {
		subQuery.add(Restrictions.eq("index", index.longValue()));
	} else {
		subQuery.add(Restrictions.isNull("index"));
	}
	ecrfFieldValueCriteria.add(Subqueries.propertyEq("id", subQuery));
}
 
Example 13
Source File: GoodsCommentDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public List<GoodsComment> findByGoodsIdAndCommentLevelAndPage(int goodsId, int commentLevel, int page, int pageSize) {
    DetachedCriteria criteria = DetachedCriteria.forClass(GoodsComment.class);

    criteria.add(Restrictions.eq("goodsid", goodsId));
    criteria.add(Restrictions.eq("commentLevel", commentLevel));
    int offset = (page - 1) * pageSize;
    return (List<GoodsComment>) template.findByCriteria(criteria, offset, pageSize);
}
 
Example 14
Source File: GoodsCommentDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public int getCountByGoodsId(int goodsId) {
    DetachedCriteria criteria = DetachedCriteria.forClass(GoodsComment.class);

    criteria.add(Restrictions.eq("goodsid", goodsId));
    criteria.setProjection(Projections.rowCount());

    Object obj  = template.findByCriteria(criteria).get(0);
    Long longObj = (Long) obj;
    int count = longObj.intValue();
    return count;
}
 
Example 15
Source File: BaseDaoTester.java    From framework with Apache License 2.0 5 votes vote down vote up
/**
 * Description: <br>
 * 
 * @author 王伟<br>
 * @taskId <br>
 *         <br>
 */
@Test
public void queryByCriteria() {
    DetachedCriteria criteria = DetachedCriteria.forClass(StudentEntity.class);
    criteria.add(Restrictions.eq(StudentEntity.AGE, NUM_18));
    List<StudentEntity> es1 = iStudentDao.queryByCriteria(criteria);

    List<StudentEntity> es2 = iStudentDao.queryByProperty(StudentEntity.AGE, NUM_18);
    Assert.isTrue(es1.size() == es2.size(), ErrorCodeDef.SYSTEM_ERROR_10001);
}
 
Example 16
Source File: UserDaoImpl.java    From Mall-Server with MIT License 5 votes vote down vote up
@Override
public List<User> getUserByPhone(String phone) {
    DetachedCriteria criteria=DetachedCriteria.forClass(User.class);
    criteria.add(Restrictions.eq("phone", phone));
    List<User> list = (List<User>) template.findByCriteria(criteria, 0, 1);
    return list;
}
 
Example 17
Source File: HomePageController.java    From TinyMooc with Apache License 2.0 5 votes vote down vote up
@RequestMapping("goPersonalNote.htm")
public ModelAndView goPersonalNote(HttpServletRequest request) {
    String userId = request.getParameter("userId");
    User user1 = userService.findById(User.class, userId);
    User user = (User) request.getSession().getAttribute("user");

    DetachedCriteria dCriteria = DetachedCriteria.forClass(UserCourse.class);
    dCriteria.add(Restrictions.eq("user", user1));

    List<UserCourse> notelist = userService.queryAllOfCondition(UserCourse.class, dCriteria);

    request.setAttribute("user1", user1);
    request.setAttribute("user", user);
    return new ModelAndView("/userPage/userNote", "notelist", notelist);
}
 
Example 18
Source File: HibernateIdentifiableObjectStore.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates a detached criteria with sharing restrictions relative to the given
 * user and access string.
 *
 * @param user   the user.
 * @param access the access string.
 * @return a DetachedCriteria.
 */
private DetachedCriteria getSharingDetachedCriteria( UserInfo user, String access )
{
    DetachedCriteria criteria = DetachedCriteria.forClass( getClazz(), "c" );

    preProcessDetachedCriteria( criteria );

    if ( !sharingEnabled( user ) || user == null )
    {
        return criteria;
    }

    Assert.notNull( user, "User argument can't be null." );

    Disjunction disjunction = Restrictions.disjunction();

    disjunction.add( Restrictions.like( "c.publicAccess", access ) );
    disjunction.add( Restrictions.isNull( "c.publicAccess" ) );
    disjunction.add( Restrictions.isNull( "c.user.id" ) );
    disjunction.add( Restrictions.eq( "c.user.id", user.getId() ) );

    DetachedCriteria userGroupDetachedCriteria = DetachedCriteria.forClass( getClazz(), "ugdc" );
    userGroupDetachedCriteria.createCriteria( "ugdc.userGroupAccesses", "uga" );
    userGroupDetachedCriteria.createCriteria( "uga.userGroup", "ug" );
    userGroupDetachedCriteria.createCriteria( "ug.members", "ugm" );

    userGroupDetachedCriteria.add( Restrictions.eqProperty( "ugdc.id", "c.id" ) );
    userGroupDetachedCriteria.add( Restrictions.eq( "ugm.id", user.getId() ) );
    userGroupDetachedCriteria.add( Restrictions.like( "uga.access", access ) );

    userGroupDetachedCriteria.setProjection( Property.forName( "uga.id" ) );

    disjunction.add( Subqueries.exists( userGroupDetachedCriteria ) );

    DetachedCriteria userDetachedCriteria = DetachedCriteria.forClass( getClazz(), "udc" );
    userDetachedCriteria.createCriteria( "udc.userAccesses", "ua" );
    userDetachedCriteria.createCriteria( "ua.user", "u" );

    userDetachedCriteria.add( Restrictions.eqProperty( "udc.id", "c.id" ) );
    userDetachedCriteria.add( Restrictions.eq( "u.id", user.getId() ) );
    userDetachedCriteria.add( Restrictions.like( "ua.access", access ) );

    userDetachedCriteria.setProjection( Property.forName( "ua.id" ) );

    disjunction.add( Subqueries.exists( userDetachedCriteria ) );

    criteria.add( disjunction );

    return criteria;
}
 
Example 19
Source File: HomePageController.java    From TinyMooc with Apache License 2.0 4 votes vote down vote up
@RequestMapping("goPersonal.htm")
public ModelAndView goPersonal(HttpServletRequest request) throws Exception {

    if ((request.getSession().getAttribute("user")) == null) {
        return new ModelAndView("redirect:goLoginPage.htm");
    } else {
        User user = (User) request.getSession().getAttribute("user");
        if ((request.getParameter("userId")).equals("")) {
            return new ModelAndView("redirect:goLoginPage.htm");
        }
        String userId = request.getParameter("userId");
        User user1 = userService.findById(User.class, userId);
        // 获取关注列表
        DetachedCriteria dCriteria1 = DetachedCriteria.forClass(Attention.class);
        dCriteria1.add(Restrictions.eq("userByUserId", user1));
        List<Attention> attentionList = userService.queryAllOfCondition(Attention.class, dCriteria1);
        // 获取好友列表
        DetachedCriteria dCriteria2 = DetachedCriteria.forClass(Attention.class);
        dCriteria2.add(Restrictions.eq("userByAttentionedUserId", user1));
        List<Attention> fansList = userService.queryAllOfCondition(Attention.class, dCriteria2);
        // 获取当前学习课程
        DetachedCriteria dCriteria3 = DetachedCriteria.forClass(UserCourse.class)
                .add(Restrictions.eq("user", user1))
                .add(Restrictions.eq("learnState", "学习中"))
                .createCriteria("course").add(Restrictions.isNull("course"));
        List<UserCourse> currentCourseList = userService.queryAllOfCondition(UserCourse.class, dCriteria3);
        // 获取当前学完课程
        DetachedCriteria dCriteria4 = DetachedCriteria.forClass(UserCourse.class);
        dCriteria4.add(Restrictions.eq("learnState", "已学"));
        dCriteria4.add(Restrictions.eq("user", user1))
                .createCriteria("course").add(Restrictions.isNull("course"));
        List<UserCourse> endCourseList = userService.queryAllOfCondition(UserCourse.class, dCriteria4);
        // 获取当前用户的标签
        DetachedCriteria dCriteria5 = DetachedCriteria.forClass(LabelObject.class);
        dCriteria5.add(Restrictions.eq("objectId", user1.getUserId()));
        List<LabelObject> labelList = userService.queryAllOfCondition(LabelObject.class, dCriteria5);
        String isOk = "";
        boolean flag = attention.isAlreadyAttention(user.getUserId(), user1.getUserId());
        if (flag) {
            isOk = "ok";
        } else {
            isOk = "no";
        }
        int credit = user1.getCredit();
        Level level = userService.getUserLevel(credit);
        request.setAttribute("isOk", isOk);
        request.setAttribute("user1", user1);
        request.setAttribute("user", user);
        request.setAttribute("level", level);
        request.setAttribute("labelList", labelList);
        request.setAttribute("labelList", labelList);
        request.setAttribute("fansList", fansList);
        request.setAttribute("currentCourseList", currentCourseList);
        request.setAttribute("endCourseList", endCourseList);

        return new ModelAndView("/userPage/user");
    }
}
 
Example 20
Source File: JournalEntryDaoImpl.java    From ctsms with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected Collection<JournalEntry> handleFindRecent(JournalModule module, Long modifiedUserId, DBModule criteriaModule, Long entityDepartmentId, boolean limit, PSFVO psf)
		throws Exception {
	org.hibernate.Criteria journalCriteria = createJournalEntryCriteria("journalEntry0");
	SubCriteriaMap criteriaMap = new SubCriteriaMap(JournalEntry.class, journalCriteria);
	if (modifiedUserId != null) {
		journalCriteria.add(Restrictions.eq("modifiedUser.id", modifiedUserId.longValue()));
	}
	if (limit) {
		applyRecentJournalEntryTimestampCriterion(journalCriteria, null);
	}
	journalCriteria.add(Restrictions.or(
			Restrictions.eq("systemMessage", false),
			Restrictions.and(Restrictions.eq("systemMessage", true), Restrictions.eq("systemMessageModule", module))));
	criteriaMap.createCriteria("category", CriteriaSpecification.LEFT_JOIN).add(Restrictions.or(Restrictions.eq("module", module), Restrictions.isNull("module")));
	DetachedCriteria subQuery = DetachedCriteria.forClass(JournalEntryImpl.class, "journalEntry1"); // IMPL!!!!
	subQuery.setProjection(Projections.max("id"));
	journalCriteria.add(Subqueries.propertyEq("id", subQuery));
	switch (module) {
		case INVENTORY_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.inventory", "journalEntry0.inventory"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("inventory").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case STAFF_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.staff", "journalEntry0.staff"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("staff").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case COURSE_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.course", "journalEntry0.course"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("course").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case USER_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.user", "journalEntry0.user"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("user").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case TRIAL_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.trial", "journalEntry0.trial"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("trial").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case PROBAND_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.proband", "journalEntry0.proband"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("proband").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		case CRITERIA_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.criteria", "journalEntry0.criteria"));
			if (criteriaModule != null) {
				subQuery.createCriteria("criteria", CriteriaSpecification.INNER_JOIN).add(Restrictions.eq("module", criteriaModule));
			}
			break;
		case INPUT_FIELD_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.inputField", "journalEntry0.inputField"));
			break;
		case MASS_MAIL_JOURNAL:
			subQuery.add(Restrictions.eqProperty("journalEntry1.massMail", "journalEntry0.massMail"));
			if (entityDepartmentId != null) {
				criteriaMap.createCriteria("massMail").add(Restrictions.eq("department.id", entityDepartmentId.longValue()));
			}
			break;
		default:
	}
	CriteriaUtil.applyPSFVO(criteriaMap, psf);
	return journalCriteria.list();
}