Here is my HQL:
Query query = createQueryOnCurrentSession("DELETE Email e " +
"where " +
"(status = :sent and creationTime <= :creation)" +
"or " +
"(status = :error and maxEttempts >= :maxEttempts)");
Here is the generated SQL:
delete from `email` where `status`=? and `creation_time`<=? or `status`=? and `attempts`>=?
Question: why are the brackets not in the SQL?
I would expect it to be:
delete from `email` where (`status`=? and `creation_time`<=?) or (`status`=? and `attempts`>=?)
may be as alternative I will delete in 2 requests?
delete from `email` where `status`=? and `creation_time`<=?
delete from `email` where `status`=? and `attempts`>=?
It’s actually a feature.
Since
andhas precedence overor, hibernate knows it, and removes brackets.You don’t need those brackets there.