Hibernate version: 2.1.6 and EHCache version 1.0
Hi All,
I seem to be having a multiple thread problem instantiating a cache. If multiple threads try to create a cache at the very same moment I get the following exception:
Code:
net.sf.hibernate.cache.CacheException: net.sf.ehcache.ObjectExistsException: Cache WhateverCache already exists
I think this would happen in general but specifially in my case it happens if I try to use a query cache in Hibernate. I am doing the following:
Code:
Query query = session.createQuery("some query");
query.setCacheable(true);
query.setCacheRegion("WhateverCache");
return query.list();
if this block of code gets executed simultaniously by more than one thread it results in the exception.
The same session is NOT used for both threads, i.e. each thread has its own session.
Is this a bug in Hibernate or EHCache? Perhaps there needs to be some syncronization code somewhere.
Here is more of the stack trace:
Code:
net.sf.hibernate.cache.CacheException: net.sf.ehcache.ObjectExistsException: Cache WhateverCache already exists
at net.sf.hibernate.cache.EhCache.<init>(EhCache.java:101)
at net.sf.hibernate.cache.EhCacheProvider.buildCache(EhCacheProvider.java:84)
at net.sf.hibernate.cache.StandardQueryCache.<init>(StandardQueryCache.java:42)
at net.sf.hibernate.cache.StandardQueryCacheFactory.getQueryCache(StandardQueryCacheFactory.java:19)
at net.sf.hibernate.impl.SessionFactoryImpl.getQueryCache(SessionFactoryImpl.java:637)
at net.sf.hibernate.loader.Loader.list(Loader.java:1011)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
Thank you,
Daniel