Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How to enable Hibernate Query Cache in JPA applications?
PostPosted: Thu Aug 09, 2007 2:35 am 
Newbie

Joined: Thu Mar 29, 2007 12:52 am
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:[/b] 3.2.4sp1, EntityManager3.3.1, Annotations3.3.0

[b]Mapping documents:[/b] N/A

[b]Code between sessionFactory.openSession() and session.close():[/b] N/A

[b]Full stack trace of any exception that occurs:[/b] N/A

[b]Name and version of the database you are using:[/b] N/A

[b]The generated SQL (show_sql=true):[/b] N/A

[b]Debug level Hibernate log excerpt:[/b] N/A


Problems with Session and transaction handling? No.

Read this: http://hibernate.org/42.html

Greetings,

I'm trying to configure Query Cache for Hibernate JPA applications.

I configured in hibernate.cfg.xml :
- hibernate.cache.use_query_cache true

From Hibernate3 Reference Chapter 19.4, I still need
- q.setCacheable(true)
to enable query cache on query q, where the method setCacheable() is available only in org.hibernate.Query but not javax.persistence.Query (and org.hibernate.Query also does not extend javax.persistence.Query).

In this case, how can we enable Hibernate Query Cache for JPA Queries in JPA applications? Or Hibernate Query Cache simply cannot be enabled in JPA applications, and we only use 2nd level cache on entities and collections?

Thanks and best regards.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 3:11 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://www.hibernate.org/hib_docs/entit ... le/#d0e797

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 4:19 am 
Newbie

Joined: Thu Mar 29, 2007 12:52 am
Posts: 6
Thanks! I got Hibernate Query Cache working by

javax.persistence.Query q;
q = em.createQuery("select object(o) from Product as o");
...
q.setHint("org.hibernate.cacheable", true);

However, I found that

query.setHint("orb.hibernate.cacheMode", CacheMode.REFRESH);

does not actually refresh the query results. I must execute

sessionFactory.evict(Product.class);

also to refresh external updates (not via Hibernate) in DB row contents.

Is this what was meant in "the query cache does not cache the state of the actual entities in the result set; it caches only identifier values and results of value type. So the query cache should always be used in conjunction with the second-level cache" in Hibernate Reference Doc?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 4:19 am 
Newbie

Joined: Thu Mar 29, 2007 12:52 am
Posts: 6
Thanks! I got Hibernate Query Cache working by

javax.persistence.Query q;
q = em.createQuery("select object(o) from Product as o");
...
q.setHint("org.hibernate.cacheable", true);

However, I found that

q.setHint("orb.hibernate.cacheMode", CacheMode.REFRESH);

does not actually refresh the query results. I must execute

sessionFactory.evict(Product.class);

also to refresh external updates (not via Hibernate) in DB row contents.

Is this what was meant in "the query cache does not cache the state of the actual entities in the result set; it caches only identifier values and results of value type. So the query cache should always be used in conjunction with the second-level cache" in Hibernate Reference Doc?


Top
 Profile  
 
 Post subject: Re: How to enable Hibernate Query Cache in JPA applications?
PostPosted: Thu May 20, 2010 4:04 am 
Newbie

Joined: Thu May 20, 2010 3:59 am
Posts: 1
I enabled q.setHint("org.hibernate.cacheable", true), but it makes query to run very very slow.

I am using ehcahce 1.2.3 and hibernate 3 and JPA(Application managed not Container managed). Please advice.

this is config for query cache in ehcache.xml
<cache
name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="5"
eternal="false"
timeToLiveSeconds="86400"
overflowToDisk="true"/>



Thanks in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 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.