JPA/Hibernate 和混乱的命名参数
我的简单查询在 JPQL 上看起来像这样:
SELECT COUNT(r) FROM org.domain.Resource r WHERE r._parent = :parent AND r._metadata[:metadataKey] is not null
但是 Hibernate SQL 输出看起来像这样(对于 H2 和 MySQL):
select
count(resource0_.id) as col_0_0_
from
resources resource0_,
resource_metadata metadata1_
where
resource0_.id=metadata1_.resource_id
and metadata1_.datum_key = ?
and resource0_.parent_id=?
and (
metadata1_.datum_value is not null
) limit ?
这里的问题是已知的 Hibernate 中的 bug 会弄乱准备好的语句参数。所以在我的例子中,父项和密钥是混合的。
除了本机查询之外,还有其他解决办法吗?
My simple query looks like this on JPQL:
SELECT COUNT(r) FROM org.domain.Resource r WHERE r._parent = :parent AND r._metadata[:metadataKey] is not null
But Hibernate SQL output looks like this (both for H2 and MySQL):
select
count(resource0_.id) as col_0_0_
from
resources resource0_,
resource_metadata metadata1_
where
resource0_.id=metadata1_.resource_id
and metadata1_.datum_key = ?
and resource0_.parent_id=?
and (
metadata1_.datum_value is not null
) limit ?
The problem here is the known bug in Hibernate which messes up prepared statement parameters. So in my case parent and key are mixed.
Any suggestions for a work around apart from native query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论