Ich muss das Ergebnis meiner Abfrage durch ein Feld bestellen, wenn nicht Null, sonst durch ein anderes Feld.Java Persistency Criteria API - Groß- und Kleinschreibung in orderBy()
Dies ist mein Code:
Expression condizione=cb.isNotNull(root.get(Attribuzione_.dataprincipale));
Expression principale=root.get(Attribuzione_.dataprincipale);
Expression creato=root.get(Attribuzione_.recordcreato);
Order ord=cb.desc(cb.selectCase()
.when(condizione, principale)
.otherwise(creato));
cq=cq.orderBy(ord);
Dieser Code verursacht eine Internal Exception: org.postgresql.util.PSQLException
, weil die Übersetzung in SQL-Code nicht die "order by" ist ich brauche:
ORDER BY CASE WHEN (t0.dataprincipale IS NOT NULL) THEN (t0.dataprincipale IS NOT NULL) ELSE t0.rec_creato END DESC
statt
ORDER BY CASE WHEN (t0.dataprincipale IS NOT NULL) THEN t0.dataprincipale ELSE t0.rec_creato END DESC
Aber ich verstehe nicht, wo ist der Fehler in meinem Code.
Irgendwelche Vorschläge? Vielen Dank
In Postrgres SQL ich normalerweise 'ORDER BY CASE schreiben ... THEN ... ELSE ... END';) Meinten Sie ' t0 SELECT *, CASE WHEN (t0.dataprincipale IS NOT NULL.) THEN t0.dataprincipale ELSE t0.rec_creato ENDE AS orderby_data VON Attribuzione t0 ORDER BY orderby_data' ? Ich versuche, es in Criteria API zu übersetzen. Es ist meine erste Annäherung ... Danke –
SQL hat historisch eine eingeschränkte Ausdruckskraft für ORDER BY-Spalten. JPA implementiert SQL-Dialekte in der Regel etwas später und weniger vollständig. Die Nähe zu einem Standard-SQL hat immer noch seinen Vorteil. –