-->
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: subselect with count with group by can't get working
PostPosted: Thu Oct 16, 2014 3:07 pm 
Newbie

Joined: Thu Oct 16, 2014 2:47 pm
Posts: 1
Hi

I'm new to hibernate and think I'm close. I'm trying to convert this simple sql
"select * from (select count(*),unit from usage group by unit) as totalusage where totalusage.count < 20;" to criteria based api.

I keep on getting into trouble in referencing total usage as an alias and in returning more than one column from my subquery.
I think I'm close
DetachedCriteria detached = DetachedCriteria.forClass(Unit.class);
Long u = new Long(20);
detached.setProjection(Projections.projectionList().add(Projections.rowCount(), "rowCount").
add(Projections.groupProperty("unit"))).addOrder(Order.desc("rowCount")).add(Restrictions.le("rowCount", u));

list = detached.getExecutableCriteria(session).list();
System.out.println(list);
and I get the error "Could not resolve rowCount".
thanks, Ollie22


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.