8

这是我的 HQL:

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

这是生成的 SQL:

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

问题:为什么括号不在SQL中?我希望它是:

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

可以替代我将在 2 个请求中删除吗?

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

2 回答 2

11

它实际上是一个功能。

由于and优先于or,hibernate 知道它,并删除括号。

你不需要那些括号。

于 2012-12-17T07:58:13.947 回答
2

逻辑运算符 AND 的优先级高于逻辑运算符 OR

对于运算符优先级,请点击链接

http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html
http://msdn.microsoft.com/en-us/library/ms190276.aspx

http://docs.oracle.com/html/A85397_01/operator.htm#997691
于 2012-12-17T08:20:19.870 回答