Hibernate HQL 中使用派生表的子查询
我有一个 Hibernate HQL 问题。 我想将子查询编写为派生表(出于性能原因)。 在 HQL 中可以做到这一点吗? 示例:(
FROM Customer WHERE country.id in
(SELECT id FROM (SELECT id FROM Country where type='GREEN') derivedTable)
顺便说一句,这只是一个示例查询,因此不要提供有关重写它的建议,这只是我感兴趣的派生表概念)
I have a Hibernate HQL question.
I'd like to write a subquery as a derived table (for performance reasons).
Is it possible to do that in HQL?
Example:
FROM Customer WHERE country.id in
(SELECT id FROM (SELECT id FROM Country where type='GREEN') derivedTable)
(btw, this is just a sample query so don't give advice on rewriting it, is just the derived table concept I'm interested in)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,派生表目前无法在 HQL 中工作。
例如,以下内容有效:
...以下内容抛出此异常:
抛出了“Antlr.Runtime.NoViableAltException”类型的异常。 1号线附近,
第 24 列 [select different Id from (select u from S2.BP.Model.User u)]
后退方法是创建一个包含原始 sql 的命名查询,或者创建一个存储过程并调用它通过命名查询,如下所示:
Unfortunately no, derived tables don't currently work in HQL.
For example, the following works:
...the following throws the this exception:
Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1,
column 24 [select distinct Id from (select u from S2.BP.Model.User u)]
The fall back would be to create a named query containing raw sql or to create a stored procedure and invoke it via named query, like so:
您可以在我的博客 http 中找到有关派生属性和性能注意事项的一些信息://blog.eyallupu.com/2009/07/hibernate-driven-properties.html
希望它会有所帮助,
埃亚卢普
You can find some information about derived properties and performance considerations on my blog in http://blog.eyallupu.com/2009/07/hibernate-derived-properties.html
Hope it will help,
Eyal Lupu