gpt4 book ai didi

sql - 在带有 Hibernate 3.2.2 的 native sql 查询中使用 IN 子句

转载 作者:行者123 更新时间:2023-12-04 00:06:13 24 4
gpt4 key购买 nike

以类似于此处找到的问题的方式:Using IN clause in a native sql query ;我正在尝试使用 IN()子句通过 Hibernate 中的 native SQL 查询。虽然另一个问题中的作者能够使用 JPA,但我不能。此外,我坚持使用 3.2.2 版。

似乎 Hibernate 不支持 IN() native 是因为它试图在应用查询参数时将我的 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() 的部分值(value)。完成这项工作的诀窍是什么?我正在使用的 Hibernate 版本会这样做吗?如果没有,我有什么选择?

提前致谢,

卡尔

最佳答案

回答了我自己的问题,应该在发布前进行 RTFM。 “诀窍”是使用 query.setParameterList()而不是 query.setParameter() .

关于sql - 在带有 Hibernate 3.2.2 的 native sql 查询中使用 IN 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5543645/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com