Hi to all, I'm a new on hibernate criteria query and I try to retrive the classic SELECT COUNT(*) FROM table WHERE .... on jpa 2.0 and hibernate 4.0.1 (I have try also 4.1, 3.6.10 and oldest)
normally for criteria query build I use something like this:
Code:
javax.persistence.criteria.CriteriaQuery cq = entityManager.getCriteriaBuilder().createQuery();
cq = entityManager.getCriteriaBuilder().createQuery();
Root<T> from = cq.from(entityClass);
cq.select(cq.from(entityClass));
.....
entityManager.createQuery(cq);
and this code work well, instead for "count" query I have trye this method:
Code:
...
cqCount.select(entityManager.getCriteriaBuilder().[b]count[/b](cq.from(entityClass)));
...
but when I call entityManager.createQuery(cq) the validator say me "No criteria query roots were specified"
I have try to search some info before to write a post here, but I have found only this example:
Code:
Criteria criteria = session.createCriteria(LogAdd.class);
criteria.add(Restrictions.gt("id", minLogID));
criteria.setProjection(Projections.rowCount());
I must use this last method for retrive a COUNT or I have missed something in my code?
thanks in advance
ps: I hope I'm in the correct section