hibernate - Disabling JPA second level cache is not working -


i use hibernate jpa web application , use apache tomcat web server. problem is, after updating entity obj, call function entity list. in entity list, see old object instead of updated one.

i check in database , record updated already. entitymanager returning old object.

here persistence.xml :

<?xml version="1.0" encoding="utf-8" ?>  <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">    <persistence-unit name="default" transaction-type="resource_local">      <description>        persistence unit envers tutorial of hibernate getting started guide      </description>      <provider>org.hibernate.jpa.hibernatepersistenceprovider</provider>      <jar-file>d:\projects\jpatempjars\com.mbc.common.jar</jar-file>      <jar-file>d:\projects\jpatempjars\com.mbc.hr.jar</jar-file>      <shared-cache-mode>none</shared-cache-mode>      <properties>        <property name="datanucleus.storemanagertype" value="true" />        <property name="hibernate.bytecode.use_reflection_optimizer" value="true" />        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.driver" />        <property name="hibernate.connection.url" value="jdbc:mysql://127.0.0.1:3306/hr" />        <property name="hibernate.connection.username" value="root" />        <property name="hibernate.connection.password" value="123123" />      </properties>    </persistence-unit>  </persistence>

here simple code updating object database...

public void updateobj(customer obj) throws exception {    entitymanager em = getentitymanager();    try {      em.gettransaction().begin();      entitymanager.merge(obj);      committransaction();    } catch (exception e) {      em.gettransaction().rollback();      throw e;    } {      em.close();    }  }

the following function getting object list database...

public objdatalist getobjlist(criteriaparams cri) throws exception {    entitymanager em = getentitymanager();    try {      string l_cri = " c.column1 '%" + cri.getkeyword() + "%' or c.column2 '%" + cri.getkeyword() + "%'";      string l_searchjpql = "select c customer c" + l_cri;      list < customer > l_entitylist = em.createquery(l_searchjpql, role.class)        .setfirstresult(cri.getindex())        .setmaxresults(cri.getsize())        .getresultlist();        objdatalist l_datalist = new objdatalist();      l_datalist.setentitylist(l_entitylist);        if (cri.getindex() == 0) {        string l_countquery = "select count(c.column1) customer c" + l_cri;        l_datalist.settotalrecord(em.createquery(l_countquery, long.class).getsingleresult());      }        return l_datalist;    } catch (exception e) {      throw e;    } {      em.close();    }  }

thanks

if want bypass cache , read database, can set cache mode refresh.

refresh update cache new findings.

see here: http://docs.oracle.com/javaee/6/tutorial/doc/gkjjj.html


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -