-->
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: Second Level Caching Problem
PostPosted: Mon Feb 27, 2006 3:20 pm 
Beginner
Beginner

Joined: Sun Jan 22, 2006 8:47 pm
Posts: 31
Hi ,

Iam trying to understand Second level Caching .I have enabled EHCache in hibernate.cfg.xml file.

<property name="hibernate.cache.provider_class">
org.hibernate.cache.EHCacheProvider
</property>


I have enabled it in hibernate.propereties file:

hibernate.cache.provider_class org.hibernate.cache.EhCacheProvider

In ehcache.xml i specified :

<cache name="pac.Appt"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="360"
timeToLiveSeconds="6000"
overflowToDisk="false"
/>

But when I try to execute a query i find the following in the log stmts:


12:11:39,073 INFO Configuration: Configuration resource: /hibernate.cfg.xml
12:11:39,323 DEBUG DTDEntityResolver: trying to locate http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
12:11:39,323 DEBUG DTDEntityResolver: found http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
12:11:39,370 DEBUG Configuration: hibernate.cache.provider_class=org.hibernate.cache.EHCacheProvider
12:11:39,370 DEBUG Configuration: hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider12:11:39,370 DEBUG Configuration: hibernate.cache.region_prefix=hibernate.test


12:11:40,151 INFO Second-level cache: enabled
12:11:40,151 INFO SettingsFactory: Query cache: disabled
12:11:40,151 INFO SettingsFactory: Cache provider: org.hibernate.cache.HashtableCacheProvider
12:11:40,151 INFO SettingsFactory: Optimize cache for minimal puts: disabled
12:11:40,151 INFO SettingsFactory: Cache region prefix: hibernate.test
12:11:40,151 INFO SettingsFactory: Structured second-level cache entries: disabled
12:11:40,151 DEBUG SQLExceptionConverterFactory: Using dialect defined converter
12:11:40,151 INFO SettingsFactory: Statistics: disabled


When I have specified EHCacheProvider why its showing HashTableCacheProvider in the log stmts..
And how can I know that this cache is actually being used from the logs?

Thnx .


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 5:43 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Maybe your session factory is looking elsewhere for the .properties or .cfg.xml files? Are you telling it where to look (using something like SessionFactory.configure("pathname"))? If it's using the defaults, are your .properties and/or .cfg.xml files in the root of your classpath?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 6:42 pm 
Expert
Expert

Joined: Mon Jan 09, 2006 5:01 pm
Posts: 311
Location: Sacramento, CA
to setup your cache do the following:
in your entities (hibernate class decls) declare them with
the appropriate
Code:
<cache usage="read-only"/>
or whatever caching strategy you want.

Then when you run your query against the entity do the following

Code:
Query q=sess.createQuery("from <your entity>");
q.setCacheMode(CacheMode.NORMAL);
q.setCacheable(true);


To see that your cache is working do:

In your code put the following:

Code:
SessionFactor sf...;

EntityStatistics estat=sf.getStatistics();

estat.getQueryCacheHitCount();

estat.getQueryCacheMissCount();


you can also getStatistics for a particular class.

Lastly my understanding of the hibernate.properties vs. hibernate.cfg.xml is this:

if you use
Code:
SessionFactory sf=new Configuration().buildSessionFactory();
then this will use the hibernate.properties

if you use:
Code:
SessionFactory sf=new Configuration().configure().buildSessionFactory();

Then this will use the hibernate.cfg.xml

The config part is referenced from Uday Kumar:
http://java.sys-con.com/read/152657.htm

_________________
-JT

If you find my replies helpful, please rate by clicking 'Y' on them. I appreciate it.


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.