java - Queries with inner object are not cached in Hibernate -


i have found, simple queries,

        session s = sessionfactory.getcurrentsession();         list<mod> list = s.createquery("from mod m m.modnameshort=:modname")                 .setparameter("modname", modname)                 .setcacheable(true)                 .list(); 

are cached well.

but cache not working one-to-many selections, this:

list<modversion> list = s.createquery("select m.modsversionses mod m")                 .setcacheable(true)                 .list(); 

it still makes requests db on second , next calls.

i have

        props.setproperty("hibernate.cache.provider_class", "org.hibernate.cache.ehcacheprovider");         props.setproperty("hibernate.cache.region.factory_class", "org.hibernate.cache.ehcache.ehcacheregionfactory");         props.setproperty("hibernate.cache.use_second_level_cache", "true");         props.setproperty("hibernate.cache.use_query_cache", "true");         factorybean.sethibernateproperties(props); 

, , mod object looks like

@entity @table(name = "mods", catalog = "artfunpw") @cache(usage = cacheconcurrencystrategy.transactional) public class mod implements java.io.serializable { ***  @onetomany(fetch = fetchtype.lazy, mappedby = "mods")      @orderby("releasedate desc")     public set<modversion> getmodsversionses() {         return this.modsversionses;     } *** 

the modversion object looks like

@entity @table(name = "mods_versions", catalog = "artfunpw", uniqueconstraints = @uniqueconstraint(columnnames = "versionnumber")) @cache(usage = cacheconcurrencystrategy.transactional) public class modversion implements java.io.serializable { 

how enable caching such one-to-many queries?

thank you!

possible, question duplicate.

i found answer here using hibernate 2nd level cache or query cache lazy fetch queries , http://docs.jboss.org/hibernate/core/3.6/reference/en-us/html_single/#performance-cache-mapping

i should add @cache(usage = cacheconcurrencystrategy.read_write) :

    @onetomany(fetch = fetchtype.lazy, mappedby = "mods", cascade = {cascadetype.all})       @orderby("releasedate desc")     @cache(usage = cacheconcurrencystrategy.read_write)      public set<modversion> getmodsversionses() {         return this.modsversionses;     } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -