File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EhCache and the fly likes Problem with ehcache Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Caching » EhCache
Bookmark "Problem with ehcache" Watch "Problem with ehcache" New topic
Author

Problem with ehcache

Nishita Jain
Ranch Hand

Joined: Mar 30, 2006
Posts: 97
Hi
I am making an application using Struts + spring + hibrnate.
I want to implement ehcache..
I have 2 questions:
1).
How do I make sure that object is coming using ehcache and not from database?
I run timer for that and that gives same result as if i am running it without ehcache.

2).
I have 2 pojo class . In one class i have used read-only and in another read-write. In my stack trace its written Like:
read-only cache configured
but I am not getting any information on Read-write cache.
I am not able to understand this.

here is stack trace:
INFO main org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
INFO main org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO main org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
INFO main org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
INFO main org.hibernate.cfg.SettingsFactory - Connection release mode: on_close
INFO main org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2
INFO main org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
INFO main org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
INFO main org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
INFO main org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO main org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
INFO main org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
INFO main org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
INFO main org.hibernate.cfg.SettingsFactory - Query cache: enabled
INFO main org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.cache.EhCacheProvider
INFO main org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
INFO main org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
INFO main org.hibernate.cfg.SettingsFactory - Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
INFO main org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
INFO main org.hibernate.cfg.SettingsFactory - Statistics: disabled
INFO main org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
INFO main org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
INFO main org.hibernate.impl.SessionFactoryImpl - building session factory
WARN main org.hibernate.cache.CacheFactory - read-only cache configured for mutable class: Book
INFO main org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
INFO main org.hibernate.cache.UpdateTimestampsCache - starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
WARN main org.hibernate.cache.EhCacheProvider - Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
INFO main org.hibernate.cache.StandardQueryCache - starting query cache at region: org.hibernate.cache.StandardQueryCache
WARN main org.hibernate.cache.EhCacheProvider - Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.

I am not able to solve this..Trying since last 3 days

Thanks in advance..
Nishita
[ March 13, 2008: Message edited by: Nishita Jain ]

Nishita
Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
1. Set the following two params in hibernate.cfg.xml so you can see the sql output. And set up some kind of logging to the console or file:
<property name="hibernate.format_sql">true</property>
<property name="hibernate.show_sql">true</property>

2. So the logging shows the Book is using read-only cache. You could always post your hbm.xml files and I could take a look.

Andy
Nishita Jain
Ranch Hand

Joined: Mar 30, 2006
Posts: 97
hey
thank you very much..
Thanks for great help.. that was really helpful.
but some doubts..
I saw this.
hibernate.show_sql -- Write all SQL statements to console. This is an alternative to setting the log category org.hibernate.SQL to debug.

hibernate.format_sql --Pretty print the SQL in the log and console.

1. I am not cleared whats the diff between them. When I set hibernate.format_sql False many info was not displayed..but still i am not clear.
2. I had already added hibernate.show_sql.. but when i added hibernate.format_sql it gave me BlockingQueue error which was the root cause of my problem.. but I dont understand why it didnt gave me error before..

3.
When i put ehcache.xml file in classpath as jar file it takes teh file but when i remove from classpath and out in web-inf dir it is not taking that file. i wrote this line also,

It gives me this,

DEBUG main org.hibernate.impl.SessionFactoryImpl - instantiating session factory with properties: {java.vendor=Sun
.
.
.
hibernate.cache.use_query_cache=true, hibernate.connection.provider_class=org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider,
, java.vm.name=Java HotSpot(TM) Client VM, hibernate.cache.provider_configuration_file_resource_path=/WEB-INF/ehcache.xml, hibernate.cache.use_second_level_cache=true, file.encoding=Cp1252, java.specification.version=1.5, hibernate.show_sql=true}
DEBUG main net.sf.ehcache.CacheManager - Creating new CacheManager with default config
DEBUG main net.sf.ehcache.CacheManager - Configuring ehcache from classpath.
WARN main net.sf.ehcache.config.ConfigurationFactory - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/apache-tomcat-6.0.2/webapps/test/WEB-INF/lib/ehcache-1.4.1.jar!/ehcache-failsafe.xml
DEBUG main net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from URL: jar:file:/D:/Training%20mat/apache-tomcat-6.0.2/webapps/test/WEB-INF/lib/ehcache-1.4.1.jar!/ehcache-failsafe.xml
DEBUG main net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from InputStream
DEBUG main net.sf.ehcache.config.DiskStoreConfiguration - Disk Store Path: D:\Training mat\apache-tomcat-6.0.2\temp
DEBUG main net.sf.ehcache.config.ConfigurationHelper - No CacheManagerEventListenerFactory class specified. Skipping...
DEBUG main net.sf.ehcache.config.ConfigurationHelper - No CachePeerListenerFactoryConfiguration specified. Not configuring a CacheManagerPeerListener.
DEBUG main net.sf.ehcache.config.ConfigurationHelper - No CachePeerProviderFactoryConfiguration specified. Not configuring a CacheManagerPeerProvider.
DEBUG main net.sf.ehcache.config.ConfigurationHelper - No BootstrapCacheLoaderFactory class specified. Skipping...
DEBUG main net.sf.ehcache.config.ConfigurationHelper - No CacheLoaderFactory class specified. Skipping...
DEBUG main net.sf.ehcache.config.ConfigurationHelper - No CacheExceptionHandlerFactory class specified. Skipping...
DEBUG main org.hibernate.cache.CacheFactory - instantiating cache region: com.wipro.pojo.Book usage strategy: read-write
WARN main org.hibernate.cache.EhCacheProvider - Could not find configuration [com.wipro.pojo.Book]; using defaults.
Can you tell me why this is happening.

Thanks,
Nishita
[ March 19, 2008: Message edited by: Nishita Jain ]
Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
I am not sure why format_sql is causing errors. For now dont worry about <property name="hibernate.format_sql">true</property>. All this does is allow the actual output to be formatted nicely.

The difference between show_sql and format_sql is that show_sql will allow the SQL generated by Hibernate to be display in your logs. The format_sql just formats the sql on multiple lines instead of a single line. format_sql is really just used for readability purposes.

I put my ehcache.xml file here: C:\java\Tomcat5.5\webapps\cms\WEB-INF\classes. This way EHCache can load the config file from the classpath. I do not custom load the config file from a specific location.
 
wood burning stoves
 
subject: Problem with ehcache
 
Similar Threads
getting errors I can't explain...anyone can help out ?
Hibernate exception problem
Could not parse configuration: /hibernate.cfg.xml
hibernate
Getting Exception Could not instantiate CacheProvider