-->
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: Hibernate : hbm2java
PostPosted: Tue Sep 27, 2005 10:34 am 
Newbie

Joined: Tue Sep 27, 2005 10:12 am
Posts: 9
Hi,
I am a newbee in Hibernate and need some help.
I am using hibernate-extensions 2.1.3 and Hibernate3
I am trying to build java classes from the hbm2java from the command line

java -cp net.sf.hibernate.tool.hbm2java.CodeGenerator Person.hbm.xml

My Person.hbm.xml file is :

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<class name="Person">
<meta attribute="class-description">
Javadoc for the Person class
@author Frodo
</meta>

<id name="id" type="long">
<meta attribute="scope-set">protected</meta>
<generator class="increment"/>
</id>
<property name="name" type="string">
<meta attribute="field-description">The name of the person</meta>
</property>
</class>

I am getting the following error :

Exception in thread "main" java.lang.NoClassDefFoundError: Person/hbm/xml

Pls help me.

Best Regards
Vasudeva


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 1:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
dont use hibernate 2 tools with hibernate 3.

use the stuff from tools.hibernate.org

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 5:25 pm 
Newbie

Joined: Tue Sep 27, 2005 10:12 am
Posts: 9
Hi,
Tried with the following versions of Hibernate and Hibernate extensions to generate Class files from a Map file:

Hibernate hibernate2.1final version
Hibernate Extensions : hibernate-extensions-2.1.3

I am getting the following error:

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)


Total time: 1 second

----------------------------------------------------------------------------

My build file is:

<?xml version="1.0"?>
<project name="BookStore Example" default="compile" basedir=".">

<!-- Set our file locations -->
<property name="source.root" value="src"/>
<property name="class.root" value="classes"/>
<property name="data.dir" value="data"/>
<property name="hibernate.home" value="/hibernate-2.1final/hibernate-2.1/" />
<property name="hibernate.tools" value="/hibernate-extensions-2.1.3/tools/" />


<!-- Set our classpath -->
<path id="project.class.path">
<!-- Include our own classes, of course -->
<pathelement location="${class.root}"/>
<!-- Include jars in the project library directory -->
<fileset dir="${hibernate.home}">
<include name="hibernate2.jar" />
</fileset>
<fileset dir="${hibernate.home}/lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${hibernate.tools}/lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${hibernate.tools}">
<include name="hibernate-tools.jar"/>
</fileset>

</path>

<!-- Load 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>

</project>
--------------------------------

My Map file is:

<?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.javasrc.books.Book" table="BOOK">
<meta attribute="class-description">
Defines a book in our bookstore database
</meta>

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

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

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

<property name="price" type="float">
<meta attribute="field-description">Retail cost of the book</meta>
</property>

<property name="publishDate" type="date">
<meta attribute="field-description">When the book was published</meta>
</property>

</class>
</hibernate-mapping>The <hibernate-mapping>

---------------------------------------------------------------------------------


Request help in generating the class files.

Regards
Vasu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 5:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you of course need to put the hibernate2.jar in the classpath to make it run.

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