EntityManager em = EMF.get().createEntityManager();
EntityTransaction tx = null;
List<Profile> list = null;
Query q = null;
try{
tx = em.getTransaction();
tx.begin();
q = em.createNamedQuery("Profile.getRandomProfile");
q.setParameter("random", Math.random());
q.setMaxResults(8);
list = (List<Profile>) q.getResultList();
if (list != null){
Collections.shuffle(list);
}
tx.commit();
} catch(NoResultException ex){
System.out.println("ERROR CATCHED: " +ex.getMessage());
if(tx != null && tx.isActive())
tx.rollback();
} catch(Exception e){
e.printStackTrace();
}
finally{
em.close();
}
リストのシャッフルにはエラーがあります:
java.lang.UnsupportedOperationException: Query result sets are not modifiable
問題を克服する方法は?