hibernate - HQL joins on many clauses

匿名 (未验证) 提交于 2019-12-03 03:06:01

问题:

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?

回答1:

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:



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!