Ecco il mio aggiornamento alla classe (Pascal Thivent):
for (int i = 0; i < orderByNames.length; i++) {
if (orderByNames[i].trim().length() > 0) {
String orderName = orderByNames[i].trim().toLowerCase();
if (orderName.contains("desc")) {
orderByNames[i] = orderName.replace("desc", "desc NULLS LAST");
} else {
orderByNames[i] = orderName.replace("asc", "asc NULLS FIRST");
}
}
}
questo risolve il problema :
Questo rompe se sql ha limite/offset dopo ordine da - Sathish 1 aprile '11 a 14:52
qui anche come è possibile utilizzare questo all'interno JPA (Hibernate):
Session session = entityManager.unwrap(Session.class);
Session nullsSortingProperlySession = null;
try {
// perform a query guaranteeing that nulls will sort last
nullsSortingProperlySession = session.getSessionFactory().withOptions()
.interceptor(new GuaranteeNullsFirstInterceptor())
.openSession();
} finally {
// release the session, or the db connections will spiral
try {
if (nullsSortingProperlySession != null) {
nullsSortingProperlySession.close();
}
} catch (Exception e) {
logger.error("Error closing session", e);
}
}
Ho provato questo su Postgres e fissa il 'nulli sono più alti rispetto ai non-valori null' problema che stavamo avendo .
Bella soluzione, non ho pensato agli intercettori, grazie! Nel caso in cui qualcun altro voglia utilizzarlo, è necessario aggiungere questa riga al file persistence.xml: –
mgamer
Questo rompe se sql ha limite/offset dopo ordine da – Sathish
Wow, che Hibernate JIRA è stato aperto nel 2005 ** ** – atrain