因此,我为此一直苦苦挣扎了大约8个小时,这是我整个移动应用程序中的最后一部分。请帮助我将此伪代码转换为有效的HQL。我在底部的内存数据库中有一个可以在H2中运行的语句,但是我的prod数据库是oracle,它很糟糕。我正在尝试获取排行榜并添加base64图像。即使我删除了下面的唯一工作H2语句,它也仍然无法运行,并显示错误`
不一致的数据类型:预期-获得CLOB
。
声明我无法在HQL工作:
select a.*, b.image
from (select distinct score.staffId as staffId,
sum(score.totalScore) as totalScore,
sum(score.timeTaken) as timeTaken from Score score) a
join User b
on a.staffId=b.staffId"
H2中的工作声明:
"select distinct score.staffId as staffId,
sum(score.totalScore) as totalScore,
sum(score.timeTaken) as timeTaken,
user.image as image"
+ " from Score score, User user"
+ " where score.staffId = user.staffId"
+ " group by score.staffId order by totalScore desc, timeTaken asc"
答案 0 :(得分:0)
尽管我对HQL一无所知,但我将从另一个角度尝试回答您的问题。
将查询重写为...
select a.*, b.image
from (
select staffId,
sum(totalScore) as totalScore,
sum(timeTaken) as timeTaken
from Score
group by staffId
) a
join User b
on a.staffId = b.staffId
...它应该可以工作。
如果仍然没有,那么您刚刚见证了称为“复杂视图合并”的Oracle查询优化器功能的奇妙之处,并且您将不得不通过no_merge
提示来稍微帮助Oracle DB ... < / p>
select a.*, b.image
from (
select --+ no_merge
staffId,
sum(totalScore) as totalScore,
sum(timeTaken) as timeTaken
from Score
group by staffId
) a
join User b
on a.staffId = b.staffId
对于您的ORM,请勿将其用于数据库读取,而应使用普通SQL或jOOQ。 ORMs are perfect at writing stuff to DB, not at reading it.