These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: .setCacheable(true) not work
PostPosted: Thu Jun 02, 2011 5:02 am 
Newbie

Joined: Wed Mar 10, 2010 4:11 am
Posts: 11
Hello, I'm trying to work query.setCacheable(true), but eclipse gives me an error:

"The method setCacheable(boolean) is undefined for the type Query
Add cast to method receiver".

I'm looking at hibernate documentation cache but do not know what I need, in all places where I look seems to work. I have in my xml:

Code:
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
<property name="hibernate.cache.use_query_cache" value="true"/>


and ehcache.xml file. Can anyone help me out? I want to cache these queries.

Greetings


Top
 Profile  
 
 Post subject: Re: .setCacheable(true) not work
PostPosted: Thu Jun 02, 2011 9:29 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
You might be using the wrong Query:

javax.persistence.Query does not support caching

Code:
org.hibernate.Query.setCacheable(boolean)


You should be able to cast our javax.persistence.Query to a org.hibernate.ejb.HibernateQuery and then use getHibernateQuery()

So this will work only with Hibernate, after all caching is not supported in JPA.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: .setCacheable(true) not work
PostPosted: Thu Jun 02, 2011 11:08 am 
Newbie

Joined: Wed Mar 10, 2010 4:11 am
Posts: 11
I think I found the solution. The query would be:

Query query = entityManager.createQuery(criteria).setHint("org.hibernate.cacheable",true);

and I have in my xml:

Code:
<property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/>
         <property name="hibernate.cache.use_query_cache" value="true"/>
         <property name="hibernate.cache.use_second_level_cache" value="true"/>


Thank you for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.