I have an Eclipse RCP application. Hibernated JARs are located in another plugin that is included in the main project in MANIFEST.MF .
I am trying to establish a simple Hibernate -> SQLite DB connection using code:
try { Configuration lConf = new Configuration(); lConf.addAnnotatedClass (eDocument.class); lConf.setProperty("hibernate.dialect", "app.sqlite.SQLiteDialect"); lConf.setProperty("hibernate.connection.driver_class", "org.sqlite.JDBC"); lConf.setProperty("hibernate.connection.url", "jdbc:sqlite:sfOrders.db"); lConf.setProperty("hibernate.connection.username", ""); lConf.setProperty("hibernate.connection.password", ""); StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(lConf.getProperties()); _sessionFactory = lConf.buildSessionFactory(builder.build()); } catch (Throwable ex) { throw new ExceptionInInitializerError(ex); }
I use native SQLiteDialect and get an error:
java.lang.ExceptionInInitializerError at app.sqlite.DatabaseConnector.connect(DatabaseConnector.java:57) at views.TransactionManagerView$6.widgetSelected(TransactionManagerView.java:144) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4362) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1113) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4180) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3769) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:654) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:598) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150) at smoothflow.Application.start(Application.java:25) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608) at org.eclipse.equinox.launcher.Main.run(Main.java:1515) at org.eclipse.equinox.launcher.Main.main(Main.java:1488) Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:244) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:208) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692) at app.sqlite.DatabaseConnector.connect(DatabaseConnector.java:55) ... 29 more Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [app.sqlite.SQLiteDialect] as strategy [org.hibernate.dialect.Dialect] at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:113) at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:162) at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:126) at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:120) at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:74) at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:51) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234) ... 42 more
I tried to compile it with the same java sleep configuration code in an empty regular java project and it works
- db: sfOrders.db exists
- without lConf.addAnnotatedClass (eDocument.class) I get the same error
- I can not use xml / hbm configs
EDIT: it must be something with the Hibernate loading class, as from what I see in the sources [Line 113], there is no simple Class.forName class, but classLoaderService: https://github.com/hibernate/hibernate-orm /blob/master/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java
I tried replacing hibernate.dialect with this:
lConf.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
Of course, there are other errors, as I use SQLite (not MySQL), but MySQLDialect was correctly found by StrategySelectorImpl.class.
To be 100% sure that my app.sqlite.SQLiteDialect exists, I created the code:
Class lClass = Class.forName("app.sqlite.SQLiteDialect");
lClass is not null
EDIT: I see that hibernate is caching some kind of loader, and it is trying to find the class inside my Eclipse RCP project with JAR instead of the main project (which includes the project with JAR). I changed the dialect to MySQLDialect.class, and the following error I received:
ClassNotFoundException: app.eCommerceCalls.eDocument cannot be found by SFLib_1.0.0
eDocument.class exists, but in the main project (not in the Eclipse RCP project with JAR [including sleep mode]). SFLib_1.0.0 - project with JAR
EDIT: So the question is how to make classes from the main RCP project visible to classes inside the JAR from the Eclipse RCP Project with libraries.
so in my case BundleLoader.class from SF1.0.0 cannot find the class from the main eDocument.class project.