caching - EclipseLink Cache not getting cached -


@namedquery(             name=dbconstants.service_by_id, query="select s service s s.id= :id",             hints={                     @queryhint(name = queryhints.query_results_cache, value = hintvalues.true),                     @queryhint(name = queryhints.query_results_cache_size, value = "500")             }) 

i using different entity manager on every query request.

query query = em.createnamedquery(dbconstants.service_by_id); query.setparameter("id", id); result = (service) query.getsingleresult(); 

this returning data database not cache.

how tested -> changed column value in database , when performed query, modified value coming. ideally should return stale data since cache not refreshed or invalidated.

revision 2:

if trying cache named queries, using multitenant aware persistence classes cause problem. how? here way think works:

@cache(         type=cachetype.soft,         size=6000,         expiry=600000 ) @multitenant @tenantdiscriminatorcolumn(...) @namedqueries({     @namedquery(             name=dbconstants.all_services, query="select s service s",             hints={                     @queryhint(name = queryhints.query_results_cache, value = hintvalues.true),                     @queryhint(name = queryhints.query_results_cache_size, value = "10")             })     }) })  @idclass(servicepk.class) public class service implements serializable { ... } 

creation of emf:

string tenantid = gettenantid(); properties.put(dbconstants.tenant_id_context_property, tenantid); properties.put(dbconstants.link_session_name, "session-" + tenantid);  if(emf == null)     emf = persistence.createentitymanagerfactory("<persistence_unit_name>", properties); 

creation of em:

em = emf.createentitymanager(); 

in case, our named query "all_services" search services , want named query cache cache based on query. when execute query, em appends tenantid query i.e.

select s service s s.tenantid = <value> 

this cached in isolated cache of l1 cache , available till use same em instance. when create new em instance, checks if entry present in l2 cache before trying invoke query on db. l2 caches based on query mentioned not tenantid appended. causes cache hit miss , call goes backend.

now... how solve problem? can remove multitenant annotations , add tenantid myself in query. tested , works absolutely fine.

but removing multitenant annotation causes lot of condition checks done manually when have dependencies on other persistence classes.

i need better solution. can help???


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -