public static <T> CriteriaQuery<Long> getCriteriaCount(Class<T> clazz,
			CriteriaBuilder cb, Object instance, Object instanceInterval,
			Map<String, OP> filterMap, Map<String, OR> sort, List<String> group) {

		/**
		 * Query result
		 */
		CriteriaQuery<Long> q = cb.createQuery(Long.class);

		/**
		 * From
		 */
		Root<T> c = q.from(clazz);

		/**
		 * Predicates
		 */
		Predicate filters = getPredicates(c, clazz, cb, instance,
				instanceInterval, filterMap, null);
		if (filters != null)
			q.where(filters);

		/**
		 * Count
		 */
		q.select(cb.count(c));

		/**
		 * Group
		 */
		if (group != null && group.size() > 0) {
			List<Expression<?>> listGroups = getGroups(c, group);
			q.groupBy(listGroups);
		}

		/**
		 * Order
		 */
		if (sort != null && sort.size() > 0) {
			List<Order> listorders = getOrders(cb, c, sort);
			if (listorders != null) {
				for (String s : sort.keySet()) {
					Path<String> path = getPath(c, s.replaceAll("\\..*", ""));
					if (path.getJavaType().getAnnotation(Entity.class) != null) {
						c.join(s.replaceAll("\\..*", ""), JoinType.INNER);
						// TODO: see problems with join created by sort, that is
						// inner
						// Join<T, Object> join = c.join(s.replaceAll("\\..*",
						// ""), JoinType.INNER);
						// q.where(cb.not(cb.isNull(join)));
					}
				}
				// q.orderBy(listorders);
				// c.join("", JoinType.LEFT);
			}
		}

		return q;
	}