我一直在阅读Hibernate文档,但没有发现任何可以解释如何执行以下操作的内容。
我尝试将以下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";
我遇到的主要问题是我无法在LEFT OUTER JOIN上有两个子句。HQL允许我拥有 ON cmd.message_key = msg.unique_key ,但是如何添加 AND clause 2?
ON cmd.message_key = msg.unique_key
AND clause 2?
您可以使用with关键字添加额外的加入条件,如下所示(取决于您的映射):
with
SELECT m, c FROM Message m LEFT JOIN m.commands c WITH (lower(c.status) = 'failed') WHERE m.sequenceReceived < 10
也可以看看: