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`>=?
Hibernate Query Language (HQL) is an object-oriented query language, similar to SQL, but instead of operating on tables and columns, HQL works with persistent objects and their properties. HQL queries are translated by Hibernate into conventional SQL queries, which in turns perform action on database.
Unlike SQL, HQL uses classes and properties in lieu of tables and columns. HQL supports polymorphism as well as associations, which in turn allows developers to write queries using less code as compared to SQL.
HQL or Hibernate Query Language is the object-oriented query language of Hibernate Framework. HQL is very similar to SQL except that we use Objects instead of table names, that makes it more close to object oriented programming.
It's actually a feature.
Since and
has precedence over or
, hibernate knows it, and removes brackets.
You don't need those brackets there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With