-->
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.  [ 10 posts ] 
Author Message
 Post subject: Eclipse 3.0 plugin can't find hibernate.cfg.xml
PostPosted: Sun Feb 26, 2006 10:17 pm 
Newbie

Joined: Mon Feb 20, 2006 9:18 am
Posts: 12
I'm having problems with Eclipse 3.0 plug finding the hibernate.cfg.xml document. I've looked and found plenty of references, but none help. Hibernate.cfg.xml is in the root of the src folder right beside the packages like this

src
+package
+anotherpackage
+yetanotherpackage
hibernate.cfg.xml.
log4j.properties

I am told that 3.1 has a method, but I'm running Win98 yet and 3.1 simply crashes within a few minutes of loading and Win98 isn't supported for 3.1. So . . . .

Any suggestions?

Roy



Hibernate version:3.0

Mapping documents:

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class" >
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/medrec
</property>
<property name="connection.username">
mm
</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<!--property name="hbm2ddl.auto">create</property-->
<mapping resource="medrecmodel/Patient.hbm.xml"/>
<mapping resource="medrecmodel/LabTest.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Patient.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate-mapping" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="medrecmodel.Patient" table="patient">
<id name="id" column="id_patient">
<generator class="native"/>
</id>
<property name="lastName" column="lastname" />
<property name="firstName" column="firstname" />
<property name="birthdate" column="birthdate" />
<property name="gender" column="gender" />

<set name="labs" table="patient_labtest">
<key column="pt_id"/>
<many-to-many column="labtest_id" class="medrecmodel.LabTest"/>
</set>
</class>
</hibernate-mapping>

LabTest.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate-mapping" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="medrecmodel.LabTest" table="labtest">
<id name="id" column="id_labtest">
<generator class="native"/>
</id>
<property name="name" column="name"/>
<property name="highValue" column = "highvalue"/>
<property name="lowValue" column = "lowvalue"/>
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

/*
* Created on Feb 16, 2006
*/
package medrecmodel;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
* @author RAD
*/
public class HibernateUtil {
private static final SessionFactory sessionFactory;
private static final Configuration cfg = new Configuration();
static {
try {
//Thread.currentThread().setContextClassLoader(HibernateUtil.getClass().getClassLoader());
//Tried a number of file paths here to steer it in the right direction, no luck
sessionFactory = cfg.configure().buildSessionFactory();
//sessionFactory = new Configuration().configure().buildSessionFactory();
}
catch(Throwable ex) {
System.out.println("HibernateUtil failed. "+ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}


Full stack trace of any exception that occurs:

java.lang.ExceptionInInitializerError
at medrecmodel.HibernateUtil.<clinit>(HibernateUtil.java:23)
at medrecmodel.Patient.getNames(Patient.java:92)
at medrecmodel.MedRecContentProvider.getElements(MedRecContentProvider.java:21)
at org.eclipse.jface.viewers.StructuredViewer.getRawChildren(StructuredViewer.java:532)
at org.eclipse.jface.viewers.StructuredViewer.getFilteredChildren(StructuredViewer.java:477)
at org.eclipse.jface.viewers.StructuredViewer.getSortedChildren(StructuredViewer.java:585)
at org.eclipse.jface.viewers.AbstractListViewer.inputChanged(AbstractListViewer.java:269)
at org.eclipse.jface.viewers.ContentViewer.setInput(ContentViewer.java:238)
at org.eclipse.jface.viewers.StructuredViewer.setInput(StructuredViewer.java:1059)
at views.PatientView.createPartControl(PatientView.java:64)
at org.eclipse.ui.internal.PartPane$2.run(PartPane.java:137)
at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:616)
at org.eclipse.core.runtime.Platform.run(Platform.java:747)
at org.eclipse.ui.internal.PartPane.createChildControl(PartPane.java:133)
at org.eclipse.ui.internal.ViewPane.createChildControl(ViewPane.java:135)
at org.eclipse.ui.internal.PartPane.createControl(PartPane.java:205)
at org.eclipse.ui.internal.ViewPane.createControl(ViewPane.java:119)
at org.eclipse.ui.internal.ViewFactory$1.run(ViewFactory.java:349)
at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:616)
at org.eclipse.core.runtime.Platform.run(Platform.java:747)
at org.eclipse.ui.internal.ViewFactory.busyRestoreView(ViewFactory.java:273)
at org.eclipse.ui.internal.ViewFactory$2.run(ViewFactory.java:530)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
at org.eclipse.ui.internal.ViewFactory.restoreView(ViewFactory.java:528)
at org.eclipse.ui.internal.ViewFactory$ViewReference.getPart(ViewFactory.java:102)
at org.eclipse.ui.internal.ViewFactory$ViewReference.getView(ViewFactory.java:166)
at org.eclipse.ui.internal.WorkbenchPage.restoreState(WorkbenchPage.java:2550)
at org.eclipse.ui.internal.WorkbenchWindow.restoreState(WorkbenchWindow.java:1372)
at org.eclipse.ui.internal.Workbench.restoreState(Workbench.java:1224)
at org.eclipse.ui.internal.Workbench.access$10(Workbench.java:1185)
at org.eclipse.ui.internal.Workbench$13.run(Workbench.java:1096)
at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:616)
at org.eclipse.core.runtime.Platform.run(Platform.java:747)
at org.eclipse.ui.internal.Workbench.restoreState(Workbench.java:1029)
at org.eclipse.ui.internal.WorkbenchConfigurer.restoreState(WorkbenchConfigurer.java:167)
at org.eclipse.ui.application.WorkbenchAdvisor.openWindows(WorkbenchAdvisor.java:652)
at org.eclipse.ui.internal.Workbench.init(Workbench.java:819)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1325)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:254)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:96)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
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.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:704)
at org.eclipse.core.launcher.Main.main(Main.java:688)
Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1287)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1309)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
at medrecmodel.HibernateUtil.<clinit>(HibernateUtil.java:18)
... 50 more


Name and version of the database you are using: MySQL 4.1

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
HibernateUtil failed. org.hibernate.HibernateException: /hibernate.cfg.xml not found


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 12:47 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That's not eclipse that's not finding your .cfg.xml file, that's your app.

Check that eclipse is copying the .xml file to the class folder. The default class folder name is bin, have a look in <project>/bin for the xml file. If it's not there, you'll want to ensure that eclipse is copying .xml files to the output folder. I don't remember where that is in eclipse 3.0, but in 3.1 that's in Window/Preferences/Java/Compiler/Building, the "Filtered Resources" text box. If *.xml is in there, remove it. You don't want to filter out xml files.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 28, 2006 9:14 am 
Newbie

Joined: Mon Feb 20, 2006 9:18 am
Posts: 12
Thanks for your response. I do find hibernate.cfg.xml in the /bin file.

Any other thoughts?

I'm getting to the point of upgrading to XP which will allow me to use 3.1. If you think that that is the best way of getting where I want to be, I'd be willing to do that.

Roy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 28, 2006 4:52 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I don't know if upgrading will help much, I don't think much changed re: configuration loading in 3.1. Debugging will probably get you further. Check the eclipse project settings, and the spelling of hibernate.cfg.xml (someone's bound to have fallen prey to typoing that). In that static block that's currrently failing, comment out all the hibernate stuff, and put in stuff to find out where in your filesystem your JVM thinks "/" is. Print out the class path, the user.* system variables, anything that might help. Try opening "/hibernate.cfg.xml" using the normal java.io classes, and copy the file to all likely directories, until your app finds it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 01, 2006 12:19 am 
Newbie

Joined: Mon Feb 20, 2006 9:18 am
Posts: 12
Thanks!

I took your advice and tried to find the home directory. I added the line to the static block that is failing:

Code:
System.out.println("home= "+System.getProperty("user.dir"));


When I run the plugin, I get: home= E:\Development\Eclipse\eclipse which doesn't work.

When I run the same as a plain old Java app, I get home= F:\Java\medrec which works fine.

Getting closer. I think you've answered my question, so you get the point for the help. I'm not clear exactly what to do next, though. How do I set up the directory structure for the plugin to make it work?

Roy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 01, 2006 12:20 am 
Newbie

Joined: Mon Feb 20, 2006 9:18 am
Posts: 12
Thanks!

I took your advice and tried to find the home directory. I added the line to the static block that is failing:

Code:
System.out.println("home= "+System.getProperty("user.dir"));


When I run the plugin, I get: home= E:\Development\Eclipse\eclipse which doesn't work.

When I run the same as a plain old Java app, I get home= F:\Java\medrec which works fine.

Getting closer. I think you've answered my question, so you get the point for the help. I'm not clear exactly what to do next, though. How do I set up the directory structure for the plugin to make it work?

Roy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 01, 2006 1:13 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It'll be somewhere in Eclipse's Windows/Preferences dialog, or maybe in the Run... dialog, if that's how you start your test/app. Look around for settings that configure the runtime root directory.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 01, 2006 3:05 pm 
Newbie

Joined: Mon Feb 20, 2006 9:18 am
Posts: 12
Making more progress. I apparently got hibernate.cfg.xml recognized by adding the following code to the static session:


Code:
File file = new File("F:/java/medrec/bin/hibernate.cfg.xml");
       sessionFactory = cfg.configure(file).buildSessionFactory();


The output was:


HibernateUtil failed. org.hibernate.MappingException: Resource: medrecmodel/Patient.hbm.xml not found

Now, of course, the problem is still there because it is not finding the package medrecmodel where the Patient.htm.xml is kept. The file structure was noted in the original post.

I looked and found lots of environment variables that can be set in the Run dialog, but I'm trying to figure out how these work. By the way, the log4j.properties file is right next to the hibernate.cfg.xml and is not being seen by the app. Getting logging output from the plugin would help me. Again, I get helpful logging output with running the app as a POJO.

Appreciate your staying with me to try to figure this out.

Roy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 01, 2006 4:43 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
log4j.properties and hibernate.cfg.xml should be in the same directory, that's good. Just have to find the correct directory. Assuming that you're running this using the Run... window (which seems likely, seeing as the root of your stack trace is org.eclipse.core.launcher), then the path you need is the one specified in Project/Properties/Java Build Path/Default output folder, which is a text box at the bottom of the dialog. It should read <project name>/bin. Then, so long as your .xml files are in the project's bin directory, they should be found.

All files in your src directory are copied to your bin directory unless the filter in the Project/Preferences/Java Compiler/Building/Filtered Resources text box matches them. So ensure that *.xml isn't in there.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 10:39 pm 
Newbie

Joined: Mon Feb 20, 2006 9:18 am
Posts: 12
Many thanks for your help.

I had the Hibernate jar files in a plugin all of its own. I removed references to that plugin and loaded the jar files in the project itself and from there, I was able to bring up the plugin fairly quickly in the runtime environment.

Thanks again!


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