-->
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.  [ 3 posts ] 
Author Message
 Post subject: newbie trying to run examples from"A Developer's Notebo
PostPosted: Fri Jan 06, 2006 9:28 pm 
Newbie

Joined: Fri Jan 06, 2006 8:56 pm
Posts: 1
Hibernate version:
hibernate-3.1

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="com.oreilly.hh.Track" table="TRACK">
<meta attribute="class-description">
Represents a single playable track in the music database.
@author Jim Elliott (with help from Hibernate)
</meta>

<id name="id" type="int" column="TRACK_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>

<property name="title" type="string" not-null="true"/>

<property name="filePath" type="string" not-null="true"/>

<property name="playTime" type="time">
<meta attribute="field-description">Playing time</meta>
</property>

<property name="added" type="date">
<meta attribute="field-description">When the track was created</meta>
</property>

<property name="volume" type="short" not-null="true">
<meta attribute="field-description">How loud to play the track</meta>
</property>

</class>
</hibernate-mapping>

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

Full stack trace of any exception that occurs:
ant codegen
C:\projects\ch02\build.xml:43: Caused by:
Caused by:
java.lang.NoClassDefFoundError: net/sf/hibernate/MappingException
at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.
java:145)
at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java
:93)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)

at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.
java:149)
at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java
:93)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)

Name and version of the database you are using:
HSQLDB 1.8.0

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

-----------------
Maybe someone with hibernate experience, after having a quick look over my post can
see where the problem is.Being a newbie, i'm
desperatly trying to go on with the book but got stuck.

Here is the problem:

I'm trying to follow the examples from the book "A Developer's Notebook",O'Reilly,2004.

downloaded source code for the book from here: http://www.oreilly.com/catalog/hibernate/

extracted /ch02 to C:\projects\ch02

I have the following installed:
apache-ant-1.6.5
hibernate-3.1
hibernate-extensions-2.1.3
hsqldb 1_8_0_2


copied everything from hibernate-3.1\lib to <Project_Dir>\lib
copied \hibernate-3.1\hibernate3.jar to <Project_Dir>\lib
copied everything from hsqldb\lib to <Project_Dir>\lib
copied everything from hibernate-extensions-2.1.3\tools\lib to <Project_Dir>\lib
Track.hbm.xml is in <Project_dir>src\com\oreilly\hh

above you can see the error after running "ant codegen"

hibernate.org FAQ says that NoClassDefFoundError might be because I'm
missing a third party library. I copied all of the jar files files that are
in the hibernate lib to the project lib folder.
A google search suggested that it might be a classpath problem.
As far as i can understand, project lib is inlcuded in the CLASSPATH
in the build.xml. Just in case i created an environment variable CLASSPATH (under windows XP SP2)
and inlcuded the directory in the project where the mapping file is located.

any suggestions?







------------------
here is the build.xml, only target "codegen" is of interest, but i
show the complete file just in case:

<?xml version="1.0"?>
<project name="Harnessing Hibernate: The Developer's Notebook"
default="db" basedir=".">

<!-- Set up properties containing important project directories -->
<property name="source.root" value="src"/>
<property name="class.root" value="classes"/>
<property name="lib.dir" value="lib"/>
<property name="data.dir" value="data"/>

<!-- Set up the class path for compilation and execution -->
<path id="project.class.path">
<!-- Include our own classes, of course -->
<pathelement location="${class.root}" />
<!-- Include jars in the project library directory -->
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</path>

<target name="db" description="Runs HSQLDB database management UI
against the database file--use when application is not running">
<java classname="org.hsqldb.util.DatabaseManager"
fork="yes">
<classpath refid="project.class.path"/>
<arg value="-driver"/>
<arg value="org.hsqldb.jdbcDriver"/>
<arg value="-url"/>
<arg value="jdbc:hsqldb:${data.dir}/music"/>
<arg value="-user"/>
<arg value="sa"/>
</java>
</target>

<!-- Teach Ant how to use Hibernate's code generation tool -->
<taskdef name="hbm2java"
classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="project.class.path"/>

<!-- Generate the java code for all mapping files in our source tree -->
<target name="codegen"
description="Generate Java source from the O/R mapping files">
<hbm2java output="${source.root}">
<fileset dir="${source.root}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>

<!-- Create our runtime subdirectories and copy resources into them -->
<target name="prepare" description="Sets up build structures">
<mkdir dir="${class.root}"/>

<!-- Copy our property files and O/R mappings for use at runtime -->
<copy todir="${class.root}" >
<fileset dir="${source.root}" >
<include name="**/*.properties"/>
<include name="**/*.hbm.xml"/>
</fileset>
</copy>
</target>

<!-- Compile the java source of the project -->
<target name="compile" depends="prepare"
description="Compiles all Java classes">
<javac srcdir="${source.root}"
destdir="${class.root}"
debug="on"
optimize="off"
deprecation="on">
<classpath refid="project.class.path"/>
</javac>
</target>

<!-- Generate the schemas for all mapping files in our class tree -->
<target name="schema" depends="compile"
description="Generate DB schema from the O/R mapping files">

<!-- Teach Ant how to use Hibernate's schema generation tool -->
<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.class.path"/>

<schemaexport properties="${class.root}/hibernate.properties"
quiet="no" text="no" drop="no">
<fileset dir="${class.root}">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>

</project>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 07, 2006 9:23 pm 
Newbie

Joined: Mon Dec 27, 2004 3:47 pm
Posts: 12
i'm going to guess that since you're using hibernate 3, and the stack trace indicates that the class not found is in "net/sf" then you'll need to search and replace

s/net.sf.hibernate/org.hibernate

you can tell this easily by looking across your classpath and ensuring that is the issue:
Code:
        for i in `find . -name '*.jar'`; do
                echo $i; jar -tf $i | grep 'MappingException'
        done


Top
 Profile  
 
 Post subject: Re: newbie trying to run examples from"A Developer's No
PostPosted: Sun Jan 08, 2006 3:58 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
rosty wrote:
Hibernate version:
hibernate-3.1

[snipped]

I have the following installed:
apache-ant-1.6.5
hibernate-3.1
hibernate-extensions-2.1.3
hsqldb 1_8_0_2



I dont think Hibernate-3.1 and Hibernate-extensions-2.1.3 may play well together. For Hibernate-3.1, the equivalent of Hibernate-extensions is available at
http://tools.hibernate.org


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