类似于这里找到的问题:Using IN clause in a native sql query;我尝试通过Hibernate中的本地SQL查询来使用
似乎Hibernate不支持
谢谢,
Carl
IN()
子句。虽然其他问题的作者能够使用JPA,但我不行。此外,我被困在3.2.2版本中。似乎Hibernate不支持
IN()
,因为它正在尝试将我的ID列表(长整型数组)转换为二进制形式,以应用查询参数:query.setParameter("publisherGroups", [1243536264532,1243536264533,1243536264535]);
来自Hibernate:
SELECT
sum(C2CReportedConversion) as c2CConversion,
sum(C2CReportedRevenue) as c2CRevenue,
sum(I2CReportedConversion) as i2CConversion,
sum(I2CReportedRevenue) as i2CRevenue,
sum(Clicks) as clicks,
sum(Impressions) as impressions,
sum(Requests) as requests,
sum(Views) as views,
coalesce(Name,
DisplayName)
FROM
UiTemplateReportingCache
JOIN
AdUnit USING (AdUnitId)
WHERE
PublisherId = ?
AND PublisherGroupId IN (
?
)
AND Date >= ?
AND Date <= ?
GROUP BY
coalesce(Name,
DisplayName)
来自mysql日志:
SELECT sum(C2CReportedConversion) as c2CConversion, sum(C2CReportedRevenue) as c2CRevenue, sum(I2CReportedConversion) as i2CConversion, sum(I2CReportedRevenue) as i2CRevenue, sum(Clicks) as clicks, sum(Impressions) as impressions, sum(Requests) as requests, sum(Views) as views, coalesce(Name, DisplayName) FROM UiTemplateReportingCache JOIN AdUnit USING (AdUnitId) WHERE PublisherId = 1239660230591 AND PublisherGroupId IN (_binary'��\0ur\0[Jx ��u�\0\0xp\0\0\0
\0\0!���T\0\0!���U\0\0!���W\0\0!���m\0\0!���n\0\0!���t\0\0!���{\0\0!���|\0\0!���}\0\0!���~\0\0#��\0\0$|��S') AND Date >= '2011-03-17 00:00:00' AND Date <= '2011-03-18 23:59:59' GROUP BY coalesce(Name, DisplayName)
注意以_binary
开头的IN()
值。让它起作用的诀窍是什么?我使用的Hibernate版本是否支持?如果不支持,我有哪些替代方案?谢谢,
Carl