我有这个HQL查询,我需要从floor(e.timestamp/(1000*60*60*24))*60*60*24
返回的值为long,但使用cast()不起作用,因为mysql不接受强制转换为BigInt或Long。我找不到正确的方法。
SELECT new DayEvent(
e.apiProxyId,
e.apiKey,
e.methodId,
floor(e.timestamp/(1000*60*60*24))*60*60*24,
sum(e.count),
e.region)
FROM Event AS e
WHERE e.timestamp <= :endTimestamp
AND e.timestamp >= :startTimestamp
GROUP BY floor(e.timestamp/(1000*60*60*24)), e.methodId, e.apiKey, e.region, e.apiProxyId`
答案 0 :(得分:0)
Hibernate支持在HQL中进行强制转换:
SELECT new DayEvent(
e.apiProxyId,
e.apiKey,
e.methodId,
cast(floor(e.timestamp/(1000*60*60*24))*60*60*24 as long),
sum(e.count),
e.region)
FROM Event AS e
WHERE e.timestamp <= :endTimestamp
AND e.timestamp >= :startTimestamp
GROUP BY floor(e.timestamp/(1000*60*60*24)), e.methodId, e.apiKey, e.region, e.apiProxyId