JPA Hibernate EHCACHE issue with onetoone associations - QueryCache -


i have entity directly mapped ui has lookup tables data not change @ all. in controller using findall on tables values , set model.

main entity

@entity public class mainentity implements serializable {     @onetoone(cascade = cascadetype.all, optional=true)     @joincolumn(name="lookup_entity_key")     private lookupentity luentity; } 

lookup entity:

@entity @table(name="lookup_entity") @cacheable public class lookupentity implements serializable {  } 

i have enabled second level cache in persistence.xml. configuration below

<property name="hibernate.cache.use_second_level_cache" value="true" /> <property name="hibernate.cache.use_query_cache" value="true" /> <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.singletonehcacheregionfactory" /> <property name="javax.persistence.sharedcache.mode" value="enable_selective" /> 

findall query cache:

entitymanager.createquery("from " + this.entityclass.getname() )                 .sethint("org.hibernate.cacheable", true)                 .getresultlist(); 

when ever request coming ui tries call findall methods in lookupentity object. reason first request calls findall sql correctly susequent request invoking findbyid sql rows present in lookupentity. behaviour expected or wrong configuration.

please help!!!

thanks!

it expected behaviour : query cache return ids of entity, , hibernate load entities themselves. entities queried cached query should in second level entity cache in order operation beneficial.

this in the documentation :

note

the query cache not cache state of actual entities in cache; caches identifier values , results of value type. reaso, query cache should used in conjunction second-level cache entities expected cached part of query result cache (just collection caching).


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -