java - JPA not receiving updated data -


i use managedbean goes db , defines bean properties db data. when update db data receive in bean not updated.

the query in db this:

    private static final string jpql_find_by_id = "select c category c c.idcategory=:id"; @override public category findcatbyid(int id) {     query query = em.createquery(jpql_find_by_id, category.class);     query.setparameter("id", id);     category cat = null;     try {         cat = (category) query.getsingleresult();     } catch (exception e) {         e.printstacktrace();     }     return cat; } 

the managed bean use category asks ejb make lookup in db:

@managedbean public class categorybean {     private string idcategorystr;     private category category;     private int id;      @ejb     private categorylookup categoryservice;      @postconstruct     public void init() {         this.category = categoryservice.findcatbyid(id); //id defined in constructor         system.out.println(this.category.getname());//this give same                                              //name before , after db update     }      public categorybean() {         facescontext fc = facescontext.getcurrentinstance();         map<string, string> paramsmap = fc.getexternalcontext()                 .getrequestparametermap();         this.idcategorystr = paramsmap.get("id");         try {             id = integer.parseint(idcategorystr);         } catch (exception e) {          }     } //get&set } 

if change title of category in db, it's gonna unchanged in bean though @postconstruct called , id correct.

<?xml version="1.0" encoding="utf-8"?> <persistence version="2.1"     xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">     <persistence-unit name="my-pu" transaction-type="jta">     <jta-data-source>jdbc/forumcsds</jta-data-source>     <class>main.java.entities.category</class>     <class>main.java.entities.country</class>     <class>main.java.entities.forum</class>     <class>main.java.entities.message</class>     <class>main.java.entities.post</class>     <class>main.java.entities.thethread</class>     <class>main.java.entities.usercfg</class>     <class>main.java.entities.usercredential</class>     <class>main.java.entities.userinfo</class>     <class>main.java.entities.user</class>     <class>main.java.entities.friend</class>     </persistence-unit> </persistence> 

reason old value entity stored in second level cache. , when request second time no database call executed, value memory returned.

you can disable cache adding <property name="eclipselink.cache.shared.default" value="false"/> property section of persistence.xml


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -