Hibernate version: 3.2 RC4
Mapping documents: none, using programatic API
I am attempting to create an EntityManagerFactory using a programatically created EJB3Configuration with device driver managernconnection info.
This is done in the context of eclipse:
1- one plugin for all of hibernate
2- one plugin for my database driver (hsqldb)
3- one plugin that depends on both to create the entity manager.
Here is the code of my entity manager creation in plugin 3:
Code:
Class.forName(org.hsqldb.jdbcDriver.class.getName());
// Configure our EJB3 EntityManagerFactory
Ejb3Configuration ejbconf = new Ejb3Configuration();
ejbconf.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
ejbconf.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
ejbconf.setProperty("hibernate.connection.url", "jdbc:hsqldb:data/example");
ejbconf.setProperty("hibernate.connection.username", "sa");
ejbconf.setProperty("hibernate.connection.password", "");
ejbconf.setProperty("hibernate.max_fetch_depth", "3");
ejbconf.setProperty("hibernate.hbm2ddl.auto", "create");
ejbconf.setProperty("hibernate.show_sql", "true");
ejbconf.addAnnotatedClass(LogRecord.class);
emf = ejbconf.buildEntityManagerFactory();
Executing this code, I get this exception at the last line:
Code:
javax.persistence.PersistenceException: org.hibernate.HibernateException: JDBC Driver class not found: org.hsqldb.jdbcDriver
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:695)
at com.hhh.logging.hibernate.test.TestDBHandler.setUp(TestDBHandler.java:55)
at junit.framework.TestCase.runBare(TestCase.java:128)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:120)
at junit.framework.TestSuite.runTest(TestSuite.java:228)
at junit.framework.TestSuite.run(TestSuite.java:223)
at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:58)
at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.run(CoreTestApplication.java:24)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)
Caused by: org.hibernate.HibernateException: JDBC Driver class not found: org.hsqldb.jdbcDriver
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1933)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:688)
... 29 more
Caused by: java.lang.ClassNotFoundException: org.hsqldb.jdbcDriver
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:407)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:352)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:83)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
... 35 more
The issue is caused by Eclipse that does not give access to hibernate (which runs in its own plugin) to access the class located in the hsqldb plugin since the hibernate plugin does not explicitely depend on this hsqldb plugin. This seems to be cause by the way the ReflectHelper class loads the device driver class.
I am waiting for feedback from eclipse as well but was wondering if anyone has an idea on how to fix this from here?
--
Michel