-->
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.  [ 4 posts ] 
Author Message
 Post subject: hibernate + junit screwy classloader problem
PostPosted: Mon Jun 21, 2004 9:12 am 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
My junit test for my hibernate store is failing (see stack trace below) if i run it from ant, but if i run the test from my IDE or if i uncheck the 'reload classes every run' in junit, it passes. clearly this is some kind of crazy classloader problem. I have the ehchache.jar file in my CP, and i have updated the excluded.properties file in my junit jar to exclude the ehcache packages. There have been lots of posts about CacheProvider classloading problems, and i've read them all, but none of the responses match this problem exactly (except one who said the latest version of hibernate fixed it, which i'm using and it didn't) anyone got any other ideas? this is killing me since i know the test really passes!

[junit] net.sf.hibernate.HibernateException: could not instantiate CacheProvider: net.sf.ehcache.hibernate.Provider
[junit] at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:133)
[junit] at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1132)
[junit] at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:766)
[junit] at store.HibernateProfileStore.initConfig(HibernateProfileStore.java:38)
[junit] at store.HibernateProfileStore.saveProfile(HibernateProfileStore.java:163)
[junit] at store.test.HibernateProfileStoreTest.testGetAndSave(HibernateProfileStoreTest.java:40)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:324)
[junit] at junit.framework.TestCase.runTest(TestCase.java:154)
[junit] at junit.framework.TestCase.runBare(TestCase.java:127)
[junit] at junit.framework.TestResult$1.protect(TestResult.java:106)
[junit] at junit.framework.TestResult.runProtected(TestResult.java:124)
[junit] at junit.framework.TestResult.run(TestResult.java:109)
[junit] at junit.framework.TestCase.run(TestCase.java:118)
[junit] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[junit] at junit.framework.TestSuite.run(TestSuite.java:203)
[junit] at junit.swingui.TestRunner$16.run(TestRunner.java:623)
[junit] Caused by: java.lang.ClassCastException
[junit] java.lang.NullPointerException
[junit] at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:130)
[junit] ... 18 more
[junit] at store.HibernateProfileStore.saveProfile(HibernateProfileStore.java:186)
[junit] at store.test.HibernateProfileStoreTest.testGetAndSave(HibernateProfileStoreTest.java:40)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[junit] at java.lang.reflect.Method.invoke(Method.java:324)
[junit] at junit.framework.TestCase.runTest(TestCase.java:154)
[junit] at junit.framework.TestCase.runBare(TestCase.java:127)
[junit] at junit.framework.TestResult$1.protect(TestResult.java:106)
[junit] at junit.framework.TestResult.runProtected(TestResult.java:124)
[junit] at junit.framework.TestResult.run(TestResult.java:109)
[junit] at junit.framework.TestCase.run(TestCase.java:118)
[junit] at junit.framework.TestSuite.runTest(TestSuite.java:208)
[junit] at junit.framework.TestSuite.run(TestSuite.java:203)
[junit] at junit.swingui.TestRunner$16.run(TestRunner.java:623)
[junit] Jun 20, 2004 10:22:19 PM net.sf.hibernate.connection.DriverManagerConnectionProvider close
[junit] INFO: cleaning up connection pool: jdbc:oracle:thin:@localhost:1521:test


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 29, 2004 8:59 pm 
Newbie

Joined: Thu Jun 10, 2004 6:04 pm
Posts: 8
I am tracking down a similar issue, but in a webapp rather than JUnit's testing UI app, and I believe this is a ClassLoader vs. Thread issue.

The net.sf.hibernate.cache.CacheProvider inteface does not have a "shutdown" method (or similar). The ehcache CacheProvider starts a checking Thread for each cache, and I believe your error stems from these Threads continued existance when the ClassLoader tries to load net.sf.ehcache.hibernate.Provider again.

Hibernate does destroy each cache from SessionFactoryImpl.close(), unfortunately net.sf.ehcache.Cache does not stop the expiry Threads it starts..

Setting overflowToDisk to "false" in ehcache.properties may alleviate your classloader issue, but if that's not the behaviour you want, you should probably appeal to the ehcache people to have their DiskStore clean up after itself.

Also, I think you must close() your SessionFactory at the end of your tests.


Top
 Profile  
 
 Post subject: correction
PostPosted: Tue Jun 29, 2004 9:05 pm 
Newbie

Joined: Thu Jun 10, 2004 6:04 pm
Posts: 8
Sorry,
Quote:
The net.sf.hibernate.cache.CacheProvider inteface does not have a "shutdown" method (or similar).

is a red herring, I meant to edit that out. I think this issue is an ehcache issue.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 29, 2004 9:58 pm 
Newbie

Joined: Thu Jun 10, 2004 6:04 pm
Posts: 8
Looks like there's a fairly new version (0.8) of ehcache available at http://ehcache.sourceforge.net/ which addresses part of the problem.

I believe that there is a further issue, and have filed a bug on that project. The way ehcache-0.8 is, you'd have to wait a maximum of 25 minutes after you shut down the SessionFactory before you could safely load things up again (run your test) if overflowToDisk is "true". It's not using the timeToIdleSeconds value from the properties file.


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