-->
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.  [ 8 posts ] 
Author Message
 Post subject: Cache Problem with 3.2 CR2
PostPosted: Sun Jun 04, 2006 11:56 am 
Newbie

Joined: Mon Mar 29, 2004 1:08 pm
Posts: 10
Hibernate version: 3.2 CR2

I've developed a desktop application that opens several Hibernate databases.

Each database uses a separate instance of SessionFactory.

I've recently upgraded to 3.2 CR2 and this is causing cache problems as indicated by the following error message:

detailMessage
"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
"C:\DOCUME~1\chas00\LOCALS~1\Temp\" which is already used by an existing CacheManager.
The source of the configuration was classpath."

The code that causes the error is:
sessionFactory = annotationConfiguration.buildSessionFactory();

This instance of sessionFactory is null before the call; therefore it is not possible to follow the suggestion in the error message (the code for each database does not have access to the instances of sessionFactory for other databases).

I'll appreciate any suggestions.

Also,
where can I locate the class net.sf.ehcache.hibernate.SingletonEhCacheProvider;
it doesn't seem to be included in the distribution.

After locating this class, what is the procedure for using it.

In advance, thanks.

Charlie


Top
 Profile  
 
 Post subject: Re: Cache Problem with 3.2 CR2
PostPosted: Sun Jun 04, 2006 12:19 pm 
Beginner
Beginner

Joined: Sat Jun 03, 2006 6:23 pm
Posts: 28
Charlie Kelly wrote:
Hibernate version: 3.2 CR2
I've recently upgraded to 3.2 CR2 and this is causing cache problems as indicated by the following error message:


Your problem might be caused by something else, but in 3.2 CR2 they upgraded from EhCache 1.1 to 1.2. Did you update that in your project?

I use the same version of Hibernate, I also use the annotationconfiguration with no error like this (I use a single database though):

Code:
    private static final SessionFactory sessionFactory;
    private static Logger logger = Logger.getLogger(HibernateUtil.class);
   
    static {
        try {
            logger.debug("Starting up Hibernate...");
            sessionFactory = new AnnotationConfiguration().configure().
                    buildSessionFactory();
            logger.debug("Starting up Hibernate: success.");
        } catch (Throwable e) {
            logger.debug("Starting up Hibernate: failure.", e);
            throw new ExceptionInInitializerError(e);
        }
    }


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 04, 2006 1:18 pm 
Newbie

Joined: Wed Apr 12, 2006 2:26 pm
Posts: 5
Hi "szroland"

Thanks for your suggestion.

I'm using EhCache1.2 (and all the other jars from the 3.2 RC2 distribution).

The problem is caused by instantiating multiple instances of SessionFactory.

There is no problem with the first instantiation; the problem occurs with the second, and subsequent databases.

Charlie


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 04, 2006 2:06 pm 
Beginner
Beginner

Joined: Sat Jun 03, 2006 6:23 pm
Posts: 28
Charlie Kelly 00 wrote:
There is no problem with the first instantiation; the problem occurs with the second, and subsequent databases.


Sorry, that wasn't really helpful then. I checked and I see your problem now.
I wonder while SingletonEhCacheProvider is missing from the ehcache-1.2 distribution, but they have it in ehcache cvs. Maybe it worth to take a look.

Roland


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 04, 2006 2:17 pm 
Beginner
Beginner

Joined: Sat Jun 03, 2006 6:23 pm
Posts: 28
Charlie Kelly 00 wrote:
The problem is caused by instantiating multiple instances of SessionFactory.


Better yet, you can actually configure for each of your session factories a different ehcache config file. I found this in the API doc, I also checked, and it works, you only need to specify different disk locations for each CacheManager.

class EhCacheProvider wrote:
When configuring multiple ehcache CacheManagers, as you would where you have multiple Hibernate Configurations and
multiple SessionFactories, specify in each Hibernate configuration the ehcache configuration using
the property <code>hibernate.cache.provider_configuration_file_resource_path</code> An example to set an ehcache configuration
called ehcache-2.xml would be <code>hibernate.cache.provider_configuration_file_resource_path=/ehcache-2.xml</code>. If the leading
slash is not there one will be added. The configuration file will be looked for in the root of the classpath.


Roland


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 04, 2006 3:21 pm 
Newbie

Joined: Wed Apr 12, 2006 2:26 pm
Posts: 5
Hi Roland,

Thanks for your research.

I'll try that method.

One potential problem: I distribute the application as an Eclipse rich client.
Therefore, I don't have access to the absolute class path where the application is intalled.

I will experiment.

Charlie


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 04, 2006 4:18 pm 
Beginner
Beginner

Joined: Sat Jun 03, 2006 6:23 pm
Posts: 28
Charlie Kelly 00 wrote:
I distribute the application as an Eclipse rich client.
Therefore, I don't have access to the absolute class path where the application is intalled.Charlie


I'm pretty sure you could get the current absolute path some way. But the ehcache descriptor should be put into your jar file, it is loaded as a resource. So they will not be separate files.


Top
 Profile  
 
 Post subject: Solution to ehcache problem in Hibernate 3.2cr2
PostPosted: Wed Jun 07, 2006 12:11 pm 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
Hi Charlie,

just upgrade your ehcache jar to ehcache-1.2.1rc,
and you problem will be solved.

Cheers
Javier Paniza


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