Good Morning everyone,
I am facing some problem in OpenJpa second level caching. Most of times caching is working but in one particular case it is not working. Here is a scenario when it is not working, When your code result null value then it store it into cache and then it never clear that value. Although it clears values only when query returns a value.
Here is code which I had written to get value from database,
List<PartnerapiworkflowEntity> partnerapiworkflowEntityList = null; try { partnerapiworkflowEntityList = entityManager.createQuery("select p from someentity p where p.id = :Id and p.name = :name and " + "p.code = :Code and p.operationname = :operationName") .setParameter("Id", Id) .setParameter("name", name) .setParameter("code", Code) .setParameter("operationName", operationName).getResultList();//.getSingleResult(); if(partnerapiworkflowEntityList != null && partnerapiworkflowEntityList.size() > 0){ return Boolean.TRUE; } } catch (NoResultException ne) { logger.severe("some logging info."); } finally { // entityManager.detach(partnerapiworkflowEntity); }
And here is a code which refresh cache.
try{ entityManager.flush(); entityManager.clear(); entityManager.getEntityManagerFactory().getCache().evictAll(); //((JpaEntityManager)entityManager.getDelegate()).getServerSession().getIdentityMapAccessor().invalidateAll(); entityManager.flush(); } catch (Exception e){ throw e; }
And this is persistence.xml code
<property name="openjpa.jdbc.DBDictionary" value="mysql"/> <property name="openjpa.DataCache" value="true(EnableStatistics=true, CacheSize=10000, SoftReferenceSize=0, EvictionSchedule='+10')"/> <!--<property name="openjpa.QueryCache" value="true(EvictPolicy='timestamp')"/>--> <property name="openjpa.QueryCache" value="false"/> <!--<property name="openjpa.jdbc.QuerySQLCache" value="true(EnableStatistics=true)"/>--> <property name="javax.persistence.sharedCache.mode" value="ENABLE_SELECTIVE"/> <property name="openjpa.Instrumentation" value="jmx(Instrument='DataCache,QueryCache,QuerySQLCache')"/> <property name="openjpa.MetaDataRepository" value="Preload=true"/> <property name="openjpa.Log" value="SQL=Trace" /> <property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" />
Everything working fine when query always returns value. The problem is start when it return null value. Then first time is store in cache and then it never refresh.
I am using OpenJpa2 and Hibernate. Help me as I am stuck here from last 3 days and I didn't get any solution.
Thanks,
1 Answers
Answers 1
You are evicting entries, but what about query cache? It can be that in normal case evicting is noticed by query case, so the result is invalidated... It can explain why null fails here. Can you please confirm?
0 comments:
Post a Comment