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
如何克服这个问题?