我更新了事务中的一个对象,它已成功更新并与数据库同步......但每当我使用query.getResultList()检索实体时,它都没有返回带有更新的对象和值的List。 / p>
这是代码指的我是怎么做的......
javax.persistence.EntityManager entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("jdbc:oracle:thin:@Siddhant-PC:1521:XEPU").createEntityManager();
javax.persistence.Query professionalWorkQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT p FROM ProfessionalWork p order by p.jobNo");
java.util.List<ProfessionalWork> professionalWorkList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : professionalWorkQuery.getResultList();
更新对象的代码......
ProfessionalWork proWork = entityManager.find(ProfessionalWork.class, jobNo);
entityManager.getTransaction().begin();
proWork.setStatus("Ready");
proWork.setReadyTime(DateWrapper.getTime());
entityManager.getTransaction().commit();
检索所有对象的代码......
professionalWorkList = professionalWorkQuery.getResultList();
Iterator lab = professionalWorkList.listIterator();
while(lab.hasNext()){
ProfessionalWork pWork = (ProfessionalWork) lab.next();
System.out.println(pWork.getJobNo()+" -- "+pWork.getStatus());
//Here i'm getting All Objects(even newly added objects also...but i'm not getting my modified values in objects)
}
professionalWorkList.clear();
答案 0 :(得分:0)
刚刚在此处引用了该文档:https://docs.oracle.com/javaee/6/tutorial/doc/gkjjj.html。很高兴它有效!
professionalWorkQuery.setHint(&#34; javax.persistence.cache.storeMode&#34;,&#34; REFRESH&#34;);