hibernate - HQL 连接许多子句

发布于 2024-11-15 12:25:05 字数 488 浏览 4 评论 0原文

我一直在阅读 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 子句 2?

I've been reading Hibernate documentation, but I haven't found anything that would explain how to do the following.

I have the following SQL code that I'm trying to convert to 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愚人国度 2024-11-22 12:25:06

您可以使用 with 关键字添加额外的连接条件,如下所示(取决于您的映射):

SELECT m, c 
FROM Message m LEFT JOIN m.commands c WITH (lower(c.status) = 'failed')
WHERE m.sequenceReceived < 10

另请参阅:

You can add extra join conditions using with keyword, something like this (depends on your mapping):

SELECT m, c 
FROM Message m LEFT JOIN m.commands c WITH (lower(c.status) = 'failed')
WHERE m.sequenceReceived < 10

See also:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文