[英]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 1-用户组
2- Users 2位使用者
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: SQL查询将是这样的:
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? 您为什么不做一个计数的
DetachedCriteria
?
Then you dc.add(Restrictions.lt(detachedCriteria, "??????????");
然后您
dc.add(Restrictions.lt(detachedCriteria, "??????????");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.