-->
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.  [ 2 posts ] 
Author Message
 Post subject: CacheException: Attempt to restart a started EhCacheProvider
PostPosted: Fri Jul 21, 2006 9:05 am 
Newbie

Joined: Fri Jun 23, 2006 3:40 pm
Posts: 11
I'm having problems acquiring an EntityManager in a multi-threaded application. Each time an EntityManager is needed it is obtained by calling the following SpiderConfig.getNewEntityManager() method:


public static EntityManager getNewEntityManager() {
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("spider");
EntityManager lEm = emf.createEntityManager();
emf.close();
return lEm;
}

I'm getting the exception below when a thread tries to get an EntityManager.

How should the EntityManagerFactory be used? Should a single shared factory instance be used in all the threads or should a new instance be created for each thread?


Exception in thread "Converter" javax.persistence.PersistenceException: org.hibernate.cache.CacheException: Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() between repeated calls to buildSessionFactory. Consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider. Error from ehcache was: Cannot parseConfiguration CacheManager. Attempt to create a new instance of CacheManager using the diskStorePath "/tmp" which is already used by an existing CacheManager. The source of the configuration was classpath.
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:217)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
at fi.kvanttisofta.spider2.config.SpiderConfig.getNewEntityManager(SpiderConfig.java:54)
at fi.kvanttisofta.spider2.Converter.runOnce(Converter.java:38)
at fi.kvanttisofta.spider2.Worker.run(Worker.java:69)
at java.lang.Thread.run(Thread.java:613)
Caused by: org.hibernate.cache.CacheException: Attempt to restart an already started EhCacheProvider. Use sessionFactory.close() between repeated calls to buildSessionFactory. Consider using net.sf.ehcache.hibernate.SingletonEhCacheProvider. Error from ehcache was: Cannot parseConfiguration CacheManager. Attempt to create a new instance of CacheManager using the diskStorePath "/tmp" which is already used by an existing CacheManager. The source of the configuration was classpath.
at org.hibernate.cache.EhCacheProvider.start(EhCacheProvider.java:133)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:180)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1213)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:151)
at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:205)
... 7 more


Top
 Profile  
 
 Post subject: Re: CacheException: Attempt to restart a started EhCacheProv
PostPosted: Fri Jul 21, 2006 10:49 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
aspa wrote:
How should the EntityManagerFactory be used? Should a single shared factory instance be used in all the threads or should a new instance be created for each thread?


Single instance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.