开发者

Java hibernate Detached criteria, count / having, query

can someone help me out with a query ?

Here´s the deal:

I have two tables

1- Group of users

2- Users

One group has a lot of users, but the thing is, the table groups holds the number of users it has on table users. But it happens that sometimes this number is invalid, I want to find the casees where the number in the table group is less then the users in the table users.

The SQL query would be like that:

select
 id_group,
 count(user)
from
 user inner join user
having 
 count(user) < group.number_of_users

In开发者_开发技巧 hibernate I cant do that, so far I got into this

DetachedCriteria dc = DetachedCriteria.forClass(Group.class);
dc.createAlias("userCollection", "uc");
dc.setProjection(Projections.count("uc.idUser"));
dc.add(Restrictions.lt("????????", "??????????");

Thanks in advance


Why don't you do a DetachedCriteria that is the count?

Then you dc.add(Restrictions.lt(detachedCriteria, "??????????");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜