を照会し、私は、エンティティの疑問を持っていると私は、データベースからの私の質問を生成するランダムはランダムに質問を生成した:私はJPQLでランダムに質問を生成したい
@Override
public List<Question> prepareRandomTest(int number_of_questions, Categorie categorie){
String jpql = "SELECT q FROM Question q where q.categorie=:categorie";
Query query = entityManager.createQuery(jpql);
query.setParameter("categorie", categorie);
query.setMaxResults(number_of_questions);
return query.getResultList();
}
これが私のメイン
Categorie categorie;
categorie=GestionCategorieDelegate.doFindCategorieById(1);
List<Question> questions=new ArrayList<>();
questions=GestionTestDelegate.doPrepareRandomTest(1, categorie);
for (Question q : questions)
{
System.out.println(q);
}
}
を入れることができますので、あなたの質問は何ですか? –
質問が無作為に表示されるようにしたい – Daly
これはおそらく役に立ちますか? http://stackoverflow.com/questions/2459119/random-select-rows-via-jpa – eol