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, "??????????");
精彩评论