-->
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.  [ 2 posts ] 
Author Message
 Post subject: Group By ... Having ... - Possible?
PostPosted: Mon Mar 27, 2006 9:44 am 
Beginner
Beginner

Joined: Wed Nov 17, 2004 11:15 am
Posts: 25
Hi,

My code so far:
Code:
Criteria itemCriteria = getSession().createCriteria(Item.class);
    itemCriteria.setProjection( Projections.projectionList()
        .add( Projections.rowCount(), "count" )
        .add( Projections.groupProperty(Item.PROPERTY_ASSET))
    );
List resultList = orderItemCriteria.list();


My aim is an SQL output like this:
...
GROUP BY this_.ASE_ID HAVING count(*) <= xxx
...

Is this possible? Or do I have to switch to HQL for this?

Cheers
Jonny


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 2:40 pm 
Beginner
Beginner

Joined: Wed Nov 17, 2004 11:15 am
Posts: 25
Hi,

since I'm pretty desperate, here the complete native sql, that I'm achieving to create with Hibernate.

SELECT *
FROM (
SELECT count(*), item.ase_id as asset
FROM Item item
GROUP BY item.ase_id HAVING count(*) <= 50
ORDER BY count(*) desc )
WHERE rownum <= 100

The hightlighted section is my problem. How can I "add" HAVING after the GROUP BY? Any advice is appreciated!!!

Thanks
Jonny


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

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.