简体   繁体   English

Java Hibernate-查询中的括号错误

[英]Java Hibernate - Wrong parenthesis in query

In my function I created a condition like this: 在我的函数中,我创建了这样的条件:

and (o.status != :shipped or (o.status = :cancelled and sp.cancelledQt != sp.requestedQt))

If I enable query logging this condition becomes: 如果启用查询日志记录,此情况将变为:

and (shipmentor0_.status<>? or shipmentor0_.status=? and positions1_.cancelledQt<>positions1_.requestedQt)

As you can see the parenthesis are in a different order than I wrote. 如您所见,括号的顺序与我写的顺序不同。

What am I doing wrong? 我究竟做错了什么?

This is because the internal parenthesis is not necessary. 这是因为不需要内部括号。 The "And" operator precedence is higher then the "Or" operator. “和”运算符的优先级高于“或”运算符。 But you can keep it to make it more readable. 但是您可以保留它以使其更具可读性。

Nothing. 没有。

Hibernate it's just taking advantage of the distributive property of the logical disjunction (fancy name for "OR") to redact your query in a more efficient way. 休眠它只是利用逻辑分离分布属性 (“ OR”的奇特名称)以一种更有效的方式来编写查询。

It is one of the pros of using an ORM instead of plain JDBC. 它是使用ORM而不是纯JDBC的优点之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM