-->
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.  [ 4 posts ] 
Author Message
 Post subject: AnnotationConfiguration (probably newbie)
PostPosted: Sun Mar 19, 2006 9:21 pm 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
I am trying to use an annotated class as the starting point. When I set up the configuration file, and add the POJO directory and the database driver, and then try to open a session factory in the hibernate console plugin, I get the following error, complaining that it cannot find the Patient class.

org.hibernate.console.HibernateConsoleRuntimeException: Could not load AnnotationConfiguration
org.hibernate.MappingException: Unable to load class declared as <mapping class="edu.utah.cdmcc.entities.Patient"/> in the configuration:
java.lang.ClassNotFoundException: edu.utah.cdmcc.entities.Patient

The directory structure is captured below:

Glucose Decision Support (PROJECT)
+++ edu.utah.cdmcc.decisionsupport.glucose
+++ +++ src
+++ +++ +++ edu.utah.cdmcc.entities
+++ +++ +++ +++ Patient.java
+++ +++ JRE System Library etc
+++ +++ Plug-In Dependencies
+++ +++ META-INF
+++ +++ hibernate.cfg.xml
etc.

Hibernate version:
Hibernate 3.1.1, plug in tools version 3.1.0.beta4a, Eclipse 3.1.2

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="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>

<mapping class="edu.utah.cdmcc.entities.Patient"/>
</session-factory>
</hibernate-configuration>

Mapping documents:
No mapping document per se. The class definition is as follows:

package edu.utah.cdmcc.entities;

import java.util.Calendar;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Patient {

private Long id;

... other stuff

private Patient() {
}

@Id
public Long getId() {
return id;
}

...other stuff

}

Full stack trace of any exception that occurs:
org.hibernate.console.HibernateConsoleRuntimeException: Could not load AnnotationConfiguration
at org.hibernate.console.ConsoleConfiguration.build(ConsoleConfiguration.java:95)
at org.hibernate.eclipse.console.actions.BuildSessionFactoryAction.doRun(BuildSessionFactoryAction.java:37)
at org.hibernate.eclipse.console.actions.ConsoleConfigurationBasedAction.run(ConsoleConfigurationBasedAction.java:46)
at org.eclipse.ui.actions.BaseSelectionListenerAction.runWithEvent(BaseSelectionListenerAction.java:167)
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:3061)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2713)
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)
Caused by: org.hibernate.MappingException: Unable to load class declared as <mapping class="edu.utah.cdmcc.entities.Patient"/> in the configuration:
at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:369)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1344)
at org.hibernate.console.ConsoleConfiguration.loadConfigurationXML(ConsoleConfiguration.java:208)
at org.hibernate.console.ConsoleConfiguration.access$0(ConsoleConfiguration.java:155)
at org.hibernate.console.ConsoleConfiguration$1.execute(ConsoleConfiguration.java:131)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:35)
at org.hibernate.console.ConsoleConfiguration.buildWith(ConsoleConfiguration.java:112)
at org.hibernate.console.ConsoleConfiguration.build(ConsoleConfiguration.java:92)
... 29 more
Caused by: java.lang.ClassNotFoundException: edu.utah.cdmcc.entities.Patient
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:405)
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:350)
at org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.loadClass(AbstractClassLoader.java:78)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:366)
... 39 more

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 1:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
have you remembered to put the classpath of your model classes into the console configuration ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Classpath
PostPosted: Wed Mar 22, 2006 6:36 pm 
Beginner
Beginner

Joined: Fri Mar 04, 2005 7:12 pm
Posts: 34
Max - Thanks. I certainly thought that I had done this correctly, but I put the path of the source. Then I put the path of the bin. But the key issue is that I was pointing too deeply into the bin.

In my case, the classnames are qualified (edu.utah.cdmcc.classX), and I was adding the path .../bin/edu/utah/cdmcc/ thinking that it would then find classX. The correct solution is obviously to only add .../bin and stop there, since the qualified names won't be visible in the "distal" folders. This is a constant problem for beginners, in Eclipse, because they easily forget the bin folder (which is hidden by default) and think they are adding things to the classpath by adding them to the project roots, folders, etc. I must have solved this problem 6 months ago but have had a few months without time to work on Hibernate.

Given the number of questions that come up over this issue, and given the popularity of Eclipse, it might be a terrific addition to the documentation materials, etc. to describe how to set up an Eclipse Hibernate project that writes out the usual feline class, etc.

Thanks very much for the work you do on this superb product.

- Mike

_________________
J. Michael Dean, MD


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 7:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I do not have time now for writing "beginners guide to java classpath/development", but I understand that it apparently is much needed thus
contributions to documentation are very welcome.

_________________
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.  [ 4 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.