Bonjour
Je ne suis pas très douée en hibernate, mais ce que je veux faire parait pourtant simple : trier mes résultats en ASC ou DESC selon une colonne donnée !
Pourtant ça ne marche pas, que je sois en ASC ou DESC j'ai invariablement le même résultat....
Voici mon code :
la sortie en ASC :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 String hqlQuery = "FROM " + m_tableName + " where priority_id=:priority order by :sortparam"; if (!p_ascending) hqlQuery = hqlQuery + " DESC"; Query query = m_em.createQuery(hqlQuery); query.setParameter("priority", p_priority.getId()); query.setParameter("sortparam", p_sortParam); List<Ticket> res = query.getResultList(); System.out.println(hqlQuery); System.out.println("sortparam : " + p_sortParam); System.out.println(res.get(0).getId()); System.out.println(res.get(1).getId()); return res;
FROM ticket where priority_id=:priority order by :sortparam
sortparam : id
ticket/5
ticket/7
la sortie en DESC
FROM ticket where priority_id=:priority order by :sortparam DESC
sortparam : id
ticket/5
ticket/7
Y a t-il une subtilité que j'ignore sur les tris en HQL ?
Partager