简体   繁体   中英

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.

It is one of the pros of using an ORM instead of plain JDBC.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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