java - How to get updated entities from JPA resultList .? -
i have updated object within transaction, updated , sync database...but whenever i'm retrieving entities using query.getresultlist() , not returning list updated objects , values.
here code refers how i'm doing...
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 professionalwork p order p.jobno"); java.util.list<professionalwork> professionalworklist = java.beans.beans.isdesigntime() ? java.util.collections.emptylist() : professionalworkquery.getresultlist();
code updating object...
professionalwork prowork = entitymanager.find(professionalwork.class, jobno); entitymanager.gettransaction().begin(); prowork.setstatus("ready"); prowork.setreadytime(datewrapper.gettime()); entitymanager.gettransaction().commit();
code retrieving objects...
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 objects(even newly added objects also...but i'm not getting modified values in objects) } professionalworklist.clear();
just referenced document here : https://docs.oracle.com/javaee/6/tutorial/doc/gkjjj.html. glad worked !
professionalworkquery.sethint("javax.persistence.cache.storemode", "refresh");
Comments
Post a Comment