org.hibernate.sql.ast.SqlTreeCreationException: Could not locate TableGroup - com.sfnt.ems.domain.common.User(144949067788000)
SqmBasicValuedSimplePath(com.sfnt.ems.domain.common.User(146863903776100).userId)
{com.sfnt.ems.domain.common.User=StandardTableGroup(com.sfnt.ems.domain.common.User(146971078538600))}
why the bracket number difference here?
CriteriaBuilder cb =restrictions.getCriteriaBuilder();
CriteriaQuery countQuery = restrictions.getCriteriaCountQuery();
Root root = restrictions.getRootCountQuery();
countQuery.select(cb.count(root));
Predicate finalPredicate=restrictions.getCriteriaQuery().getRestriction();
if(finalPredicate!=null)
countQuery.where(cb.and(finalPredicate));
Query queryCount = getSession().createQuery(countQuery);
Long count = (Long) queryCount.getSingleResult();
return count.intValue();
My restriction class has methods as:
public class Restrictions {
private CriteriaBuilder builder;
private Class<T> persistentClass;
private CriteriaQuery<T> criteriaQuery = null;
private CriteriaQuery<Long> criteriaCountQuery = null;
private Root<T> root = null;
private Root<T> rootCountQuery = null;
public Restrictions(CriteriaBuilder criteriaBuilder, Class<T> persistentClass) {
this.persistentClass = persistentClass;
builder = criteriaBuilder;
}
public CriteriaBuilder getCriteriaBuilder() {
return builder;
}
public CriteriaQuery<T> getCriteriaQuery() {
if (criteriaQuery == null)
criteriaQuery = builder.createQuery(this.persistentClass);
return criteriaQuery;
}
public CriteriaQuery<Long> getCriteriaCountQuery() {
if (criteriaCountQuery == null)
criteriaCountQuery = builder.createQuery(Long.class);
return criteriaCountQuery;
}
public Root<T> getRootCountQuery() {
if (rootCountQuery == null)
rootCountQuery = getCriteriaCountQuery().from(this.persistentClass);
rootCountQuery.alias(this.persistentClass.getName());
return rootCountQuery;
}
public Root<T> getRoot() {
if (root == null)
root = getCriteriaQuery().from(this.persistentClass);
root.alias(this.persistentClass.getName());
return root;
}
}