To get list of 10 random unique objects with Hql I have this methode but i had an error
String sRequete = "select p from TgQuestionnaire p where p.id.idAnnee = :paramAnnee order by rand()";
try{
//sRequete = sRequete + " order by p.id.cdQuestionnaire ";
Query requete = entityManager.createQuery(sRequete);
if (resultat_max != null && resultat_max > 0) {
requete.setMaxResults(resultat_max);
}
requete.setParameter("paramAnnee", idAnnee);
listeEnteteQuestionnaire = (List<TgQuestionnaire>) requete
.getResultList();
if (listeEnteteQuestionnaire.size() == 0) {
listeEnteteQuestionnaire = new ArrayList<TgQuestionnaire>();
}
} catch (Exception e) {
log.error("erreur bdd pendant la recherche des entêtes de questionnaire :"
+ e.getMessage());
}
return listeEnteteQuestionnaire;
}
ERROR: 2015/04/03 16:14:39,264 WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 904, SQLState: 42000 2015/04/03 16:14:39,264 ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00904: "RAND" : identificateur non valide
Aucun commentaire:
Enregistrer un commentaire