Java – parentheses in HQL cannot be converted to SQL

This is my HQL:

Query query = createQueryOnCurrentSession("DELETE Email e " +
                "where " +
                "(status = :sent and creationTime <= :creation)" +
                "or " +
                "(status = :error and maxEttempts >= :maxEttempts)");

This is the generated SQL:

delete from `email` where `status`=? and `creation_time`<=? or `status`=? and `attempts`>=?

Question: Why are parentheses not in SQL? I hope it is:

delete from `email` where (`status`=? and `creation_time`<=?) or (`status`=? and `attempts`>=?)

Maybe I'll delete it in 2 requests?

delete from `email` where `status`=? and `creation_time`<=?
delete from `email` where `status`=? and `attempts`>=?

Solution

This is actually a function

Since and take precedence over or, hibernate knows it and removes the parentheses

You don't need those brackets

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>