我有一個實體問題,我想生成數據庫我的問題隨機隨機生成的問題:我要生成與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