【问题标题】:Convert from Int to Long in Hibernate HQL using MySQL 5.5使用 MySQL 5.5 在 Hibernate HQL 中从 Int 转换为 Long
【发布时间】:2015-02-18 02:56:29
【问题描述】:

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

【问题讨论】:

    标签: mysql hibernate hql


    【解决方案1】:

    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
    

    【讨论】:

    • 我确实尝试过,但它不起作用,因为 MySQL 将 long 视为 bigint,并且不支持强制转换为 bigint。 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    相关资源
    最近更新 更多