Hier ntranslated ist mein HQL:Brackets in HQL nicht auf SQL
Query query = createQueryOnCurrentSession("DELETE Email e " +
"where " +
"(status = :sent and creationTime <= :creation)" +
"or " +
"(status = :error and maxEttempts >= :maxEttempts)");
Hier ist die erzeugte SQL:
delete from `email` where `status`=? and `creation_time`<=? or `status`=? and `attempts`>=?
Frage: Warum sind die Klammern nicht in der SQL? Ich würde erwarten, dass es sein:
delete from `email` where (`status`=? and `creation_time`<=?) or (`status`=? and `attempts`>=?)
kann als Alternative I in 2 Anfragen löschen wird?
delete from `email` where `status`=? and `creation_time`<=?
delete from `email` where `status`=? and `attempts`>=?
versuchen, die Klammern zu entkommen etwa so: '\ (' –
Single '“ \ ("' kompiliert (natürlich) nicht und verdoppelt '" \\ ("' Ausnahme auslösen: 'org.hibernate.QueryException: unexpected char: '\' [DELETE com.grroo.model.Email e where \ (status =: sended und creationTime <=: creation \) oder \ (status =: error und versuche> =: maxAttempts \)] ' – urir
Ich denke du kann Abfrage-String als Ihre Bedingung dann ausführen –