I have Eclipse RCP Application. JARs with hibernate are in another plugin which is included in the main project in MANIFEST.MF
.
I try to establish simple connection Hibernate -> SQLite
DB 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 custom SQLiteDialect and i get 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 hibernate configuration Java code in empty normal Java project and it works
EDIT: it must be something with the way Hibernate load classes as from what I see in sources [Line 113], there is no simple Class.forName but classLoaderService: https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/internal/StrategySelectorImpl.java
I have tried replace 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 is found properly by StrategySelectorImpl.class.
To be 100 % sure that my app.sqlite.SQLiteDialect exists i created code:
Class lClass = Class.forName("app.sqlite.SQLiteDialect");
lClass is not null
EDIT: I see that hibernate caches some kind of loader and it tries to find class inside my Eclipse RCP project with JARs instead of main project (in which the project with JARs is included). I changed dialect to MySQLDialect.class and next error i got is:
ClassNotFoundException: app.eCommerceCalls.eDocument cannot be found by SFLib_1.0.0
eDocument.class exists but in main project (not in Eclipse RCP Project with JARs [including hibernate]). SFLib_1.0.0 - project with JARs
EDIT: So the question is, how to make classes from main RCP project visible for classes inside JAR from Eclipse RCP Project with libraries.
so in my case, the BundleLoader.class from SF1.0.0 can't find a class from main project eDocument.class.
Try to replace this line:
lConf.setProperty("hibernate.dialect", "app.sqlite.SQLiteDialect");
With:
lConf.setProperty("dialect", "app.sqlite.SQLiteDialect");