Have tried several approaches. First, tried the Eclipse-BuddyPolicy but am very unsure I did this correctly. Second, tried altering the classloader in two different places, neither successful. I describe each below.
I edited the manifest.mf file of the org.hibernate.eclipse plugin and added on the last line
Eclipse-BuddyPolicy: registered
and in my own manifest.mf I added (only one at a time, but none worked)
Eclipse-BuddyPolicy: hibernate
Eclipse-BuddyPolicy: org.hibernate.eclipse
Eclipse-BuddyPolicy: org.hibernate.eclipse.jar
Moving on to altering the classLoader, I first attempted to do this from in the createPartControl that calls HibernateUtil after it sets up my view; I reasoned that this code is in the same project as all the rest of my code, and HibernateUtil is in my codebase. After this failed, I changed HibernateUtil only in the static initializer because that is where the stack trace points, as follows:
Code:
// Create the initial SessionFactory from the default configuration files
static {
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
configuration = new Configuration();
sessionFactory = configuration.configure().buildSessionFactory();
// We could also let Hibernate bind it to JNDI:
// configuration.configure().buildSessionFactory()
} catch (Throwable ex) {
// We have to catch Throwable, otherwise we will miss
// NoClassDefFoundError and other subclasses of Error
log.error("Building SessionFactory failed.", ex);
throw new ExceptionInInitializerError(ex);
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
This failed. The stacktrace for the failure does not indicate any classLoader issues that I can detect:
Code:
08:34:44,519 INFO HibernatePlugin:21 - HibernatePlugin Started
08:34:44,559 INFO Environment:464 - Hibernate 3.0.5
08:34:44,561 INFO Environment:477 - hibernate.properties not found
08:34:44,568 INFO Environment:510 - using CGLIB reflection optimizer
08:34:44,572 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
08:34:44,635 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml
08:34:44,636 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml
08:34:44,637 WARN Configuration:1086 - /hibernate.cfg.xml not found
08:34:44,643 ERROR HibernateUtil:43 - Building SessionFactory failed.
org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1087)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1111)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)
at edu.utah.cdmcc.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:37)
at edu.utah.cdmcc.application.View.createPartControl(View.java:70)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:305)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.java:180)
at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:552)
at org.eclipse.ui.internal.Perspective.showView(Perspective.java:1655)
at org.eclipse.ui.internal.WorkbenchPage.busyShowView(WorkbenchPage.java:930)
at org.eclipse.ui.internal.WorkbenchPage.access$12(WorkbenchPage.java:913)
at org.eclipse.ui.internal.WorkbenchPage$13.run(WorkbenchPage.java:3148)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:3145)
at org.eclipse.ui.internal.WorkbenchPage.showView(WorkbenchPage.java:3123)
at org.eclipse.ui.handlers.ShowViewHandler.openView(ShowViewHandler.java:146)
at org.eclipse.ui.handlers.ShowViewHandler.openOther(ShowViewHandler.java:102)
at org.eclipse.ui.handlers.ShowViewHandler.execute(ShowViewHandler.java:70)
at org.eclipse.ui.internal.ShowViewMenu$3.run(ShowViewMenu.java:113)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:996)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:538)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:488)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:400)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1380)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1404)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1389)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1237)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3060)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2712)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1699)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1663)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:367)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:143)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:103)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:226)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:376)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:163)
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:334)
at org.eclipse.core.launcher.Main.basicRun(Main.java:278)
at org.eclipse.core.launcher.Main.run(Main.java:973)
at org.eclipse.core.launcher.Main.main(Main.java:948)
Unhandled event loop exception
Reason:
java.lang.ExceptionInInitializerError
Following the stacktrace into the Configuration.java source, the Hibernate code is specifying its own context classLoader (I think, line 1061 of current CVS), but is clearly not finding the configuration file.
I cannot use the approach which is to put all the code, including Hibernate code, into one large jar, because we want to use the Eclipse platform in order to add functionality over time with additional plugins.
I have several hypotheses:
1. When I edited the manifest.mf in the org.hibernate.eclipse plugin distributed from JBoss, maybe this is stupid, and I have to actually rebuild the plugin. I tried with a CVS load, but it is not clear how to set this up because the lib folder is empty.
2. I used the wrong syntax for the BuddyPolicy mechanism. This is clearly the best mechanism from convenience standpoint, but I can't figure out the way to implement it.
3. I am (obviously) placing the classLoader code in the wrong place.
4. Maybe the code is being found appropriately, but I have the hibernate.cfg.xml file in the wrong place. I have clicked on it to add it to the build, but not sure how to verify it actually gets put IN the build.
I appreciate any assistance. Thank you.