-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Criteriaquery question...
PostPosted: Fri Feb 24, 2012 11:27 am 
Newbie

Joined: Fri Feb 24, 2012 10:58 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.