-->
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.  [ 15 posts ] 
Author Message
 Post subject: Eclipse Classpath (I Tried!)
PostPosted: Mon Jul 04, 2005 3:57 pm 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
Have set up a project with hibernate.cfg.xml in the src directory and it is copied to the bin directory; it refers to mapping files. All is well when I run tests on this in the Eclipse IDE. However, when I create the plugin and try to access Hibernate, it is not finding hibernate.cfg.xml.

In the "add classpath section" of the manifest editor, I have added the bin folder, the main library being compiled, the src folder, all of the above, to no avail.

Help will be appreciated. I KNOW this is a frequent problem and have spent hours poring over documentation and Forum archives.

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 4:00 pm 
Beginner
Beginner

Joined: Wed May 18, 2005 9:48 am
Posts: 31
I don't know how works Eclipse but in netbeans you have to put hibernate.hmb.xml in the src/WEB-INF/classes directory.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 4:55 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Try to set thread context loader manualy before to load mappings.
"Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader())"


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 6:44 pm 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
Not sure what you mean - mostly not sure where I would insert this kind of code - into the configuration code for the sessionfactory??

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 8:20 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Try set hibernate.cfg.xml in plugin's src folder

regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 8:52 pm 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
Thanks. It is in the src folder as well as the bin folder.

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 8:54 pm 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
I am thinking that there may be a problem that the xml files are not in jar files, so perhaps Eclipse does not actually move the hibernate.cfg.xml and the hbm.xml files where I think it moves them. Has this been a problem?

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 04, 2005 9:19 pm 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
I tried just sticking the hibernate.cfg.xml file in its own plugin, but this did not solve the problem.

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 4:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
search for context classloader hibernate and eclipse and you will find the issue is that eclipse does not set the context classloader to something that makes it possible to use hibernate (or log4j, spring, aop, etc.) easily in eclipse.

The best workaround is as baliukas tells you OR to bundle everything in one big plugin (or set up some very weird dependencies ;)

in the recent eclipse 3.1 they introduced buddy classloading which i unfortunately have not looked into yet, but it should apparently solve some of these issues.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 5:01 pm 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
Thanks. Will try the Eclipse buddy approach - tried naively but forgot that it is the Hibernate library that needs access to my code, not the other way around.

I interpret your alternative of "one large plugin" as putting all the hibernate libraries inside the same plugin with my own code. Correct?

Thanks.

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 5:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 11:03 am 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
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.

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 12:07 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Michael,
I try eclipse buddy and it work fine :

- hibernate core libararies plugin with id, for example, org.hibernate.eclipse

in MANIFEST.MF set next :

Eclipse-BuddyPolicy: registered

my plugin with id : my.plugin

in MANIFEST.MF set this :

Eclipse-RegisterBuddy: org.hibernate.eclipse

in my plugin I copy Christian's HibernateUtil and in plugin start method call

Class.forName("my.plugin.HibernateUtil"); // full class name

hibernate.cfg.xml is in src directory in my.plugin

It work fine

see : id name plugin which find classes/resource from another plugin (org.hibernate.eclipse)
declarations are :
Eclipse-BuddyPolicy
and
Eclipse-RegisterBuddy

regards
[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 2:45 pm 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
Thank you. This worked!

For other souls following this same path, key issues:

You can directly edit the manifest.mf file, and add to org.hibernate.eclipse the line

Eclipse-BuddyPolicy: registered

and to your own code manifest.mf add the line

Eclipse-RegisterBuddy: org.hibernate.eclipse

and if you use Christian's HibernateUtil as I have, then add the following line to your plugin start method:

Class.forName("my.plugin.HibernateUtil"); // full class name

and all will be well. I was using the wrong syntax in my own manifest by stating BuddyPolicy again instead of RegisterBuddy.

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 5:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Would appreciate if you put this on our Wiki - thank you

_________________
Max
Don't forget to rate


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