SQL hibernate - HQL 在许多子句上加入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6345052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
hibernate - HQL joins on many clauses
提问by iliaden
I've been reading Hibernate documentation, but I haven't found anything that would explain how to do the following.
我一直在阅读 Hibernate 文档,但没有找到任何可以解释如何执行以下操作的内容。
I have the following SQL code that I'm trying to convert to HQL:
我有以下 SQL 代码,我正在尝试将其转换为 HQL:
SELECT {msg.*}, {cmd.*}
FROM Schema.Messages AS msg
LEFT OUTER JOIN schema.send_commands AS cmd
ON cmd.message_key = msg.unique_key
AND ( lower(cmd.status) IN (lower('failed') ) )
WHERE msg.sequence_received < 10";
The mainissue I'm having is that I'm unable to have two clauses on a LEFT OUTER JOIN. HQL allows me to have
ON cmd.message_key = msg.unique_key
, but how do I add the
AND clause 2?
我遇到的主要问题是我无法在 LEFT OUTER JOIN 上有两个子句。HQL 允许我拥有
ON cmd.message_key = msg.unique_key
,但如何添加
AND clause 2?
回答by axtavt
You can add extra join conditions using with
keyword, something like this (depends on your mapping):
您可以使用with
关键字添加额外的连接条件,如下所示(取决于您的映射):
SELECT m, c
FROM Message m LEFT JOIN m.commands c WITH (lower(c.status) = 'failed')
WHERE m.sequenceReceived < 10
See also:
也可以看看: