我有一个带有计算属性的实体组,我正在尝试使用 @Formula 进行计算。还有其他三个实体具有该实体的外键,我要计算的是有多少实体依赖于每个 Group 实体,因此公式如下所示:public class Group {...@Formula("(select count (distinct (s.id)) + count(distinct(ses.id)) + count (distinct(u.id)) from section s, session ses, user u, group_user gu where s.group_id = id and ses.group_id = id and gu.user_id = u.id and gu.group_id = id )") private int dependencies;}但是当我在 Group 上执行 findAll 时,它会抛出异常:ORA-00904: "GROUP0_"."COUNT": invalid identifier生成的 SQL 看起来很奇怪,像这样: Hibernate: select * from ( select distinct group0_.id as id1_8_, group0_.active as active2_8_, group0_.code as code3_8_, ... (select group0_.count (distinct (s.id)) + count(distinct(ses.id)) + group0_.count (distinct(u.id)) from section s, session ses, user u, group_user gu where s.group_id = group0_.id and ses.group_id = group0_.id and gu.user_id = u.id and gu.group_id = group0_.id ) as formula1_ from group group0_ where 1=1 order by group0_.code asc ) where rownum <= ?我应该如何编写公式才能使其发挥作用?
1 回答
12345678_0001
TA贡献1802条经验 获得超5个赞
最后这只是一个愚蠢的问题:count 和 ( 如果我写公式:
@Formula("(select count(distinct (s.id)) + count(distinct(ses.id)) + count(distinct(u.id)) from section s, session ses, user u, group_user gu where s.group_id = id and ses.group_id = id and gu.user_id = u.id and gu.group_id = id )")
有用!!
添加回答
举报
0/150
提交
取消