playframework / playframework/play1

Can't use hibernate second level cache in 1.4.4

Open
#1,117 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.6k
Forks
671
Avg merge
12d 15h
Merged PRs (30d)
1

Description

Referencing #952 I've tried to get this working in 1.4.4 but am getting errors. If I add this to my application.conf

hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.EhCacheRegionFactory

I get the following error:

Oops: PersistenceException
Unexpected error : Unexpected Error, caused by exception PersistenceException: Unable to build EntityManagerFactory

play.exceptions.UnexpectedException: Unexpected Error
	at play.Play.start(Play.java:571)
	at play.Play.detectChanges(Play.java:659)
	at play.Invoker$Invocation.init(Invoker.java:209)
	at Invocation.HTTP Request(Play!)
Caused by: javax.persistence.PersistenceException: Unable to build EntityManagerFactory
	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:925)
	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:900)
	at play.db.jpa.JPAPlugin.onApplicationStart(JPAPlugin.java:198)
	at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:616)
	at play.Play.start(Play.java:541)
	... 3 more
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:211)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:175)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:267)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1799)
	at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:918)
	... 7 more
Caused by: org.hibernate.cache.CacheException: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ]
	at org.hibernate.cache.ehcache.EhCacheRegionFactory.start(EhCacheRegionFactory.java:110)
	at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:70)
	at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40)
	at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35)
	at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:91)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:201)
	... 13 more
Caused by: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
The source of the existing CacheManager is: DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ]
	at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:529)
	at net.sf.ehcache.CacheManager.init(CacheManager.java:374)
	at net.sf.ehcache.CacheManager.<init>(CacheManager.java:259)
	at org.hibernate.cache.ehcache.EhCacheRegionFactory.start(EhCacheRegionFactory.java:83)
	... 18 more

I noticed that the package name for EhCacheRegionFactory in the newly included jar was org.hibernate.cache.ehcache.EhCacheRegionFactory but setting that in the application.conf also errors. Is anyone else able to get this working?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the cache settings in application.conf and the JPA startup path in play.db.jpa.JPAPlugin, then compare the configured EhCacheRegionFactory package with the stack trace. Reproduce the EntityManagerFactory failure and confirm a working second-level-cache configuration without the duplicate unnamed CacheManager error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.