使用MySQL 5.5在Hibernate HQL中从Int转换为Long

时间:2015-02-18 02:56:30

标签: mysql hibernate hql

我有这个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`

1 个答案:

答案 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