-->
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.  [ 6 posts ] 
Author Message
 Post subject: Confused hbm2java
PostPosted: Sat Oct 15, 2005 6:02 pm 
Newbie

Joined: Sat Oct 15, 2005 5:45 pm
Posts: 18
I have just started to read the "Hibernate - A developers notebook" from OReilly.

I have downloaded from hibernate.org

Hibernate Core 3.1 rc1
Hibernate Tools 3.1 alpha 5 (eclipse plugins)

I couldn't find hibernate extensions as detailed in the book, so a google search identified that it was available from sourceforge.net. I downloaded

hibernate-extensions-2.1.3

The error I initially got was:

BUILD FAILED
C:\TigerSoft\Trunk\LearningZone\Hibernate\build.xml:40: taskdef class net.sf.hib
ernate.tool.hbm2java.Hbm2JavaTask cannot be found

It was immediately obvious that my hibernate extensions jar file didn't have that path so I tried hacking the build document (which is in full below) which changed the error to this:

BUILD FAILED
C:\TS\Trunk\LearningZone\Hibernate\build.xml:44: Could not create type hb
m2java due to java.lang.NoSuchMethodException: org.hibernate.tool.ant.Hbm2JavaGe
neratorTask.<init>(org.apache.tools.ant.Project)

What the hell am I doing wrong? The book may be using an earlier version of Hibernate, so any advice would be great.

Hibernate version: 3.1 rc1

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():
Dunno what this is yet!

Full stack trace of any exception that occurs:
Buildfile: build.xml

codegen:

BUILD FAILED
C:\TS\Trunk\LearningZone\Hibernate\build.xml:44: Could not create type hb
m2java due to java.lang.NoSuchMethodException: org.hibernate.tool.ant.Hbm2JavaGe
neratorTask.<init>(org.apache.tools.ant.Project)

Total time: 2 seconds

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

The generated SQL (show_sql=true):
Problem is not with SQL generation

Debug level Hibernate log excerpt:
Not available.

The build file:

<?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>

<!-- classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask" -->
<!-- Teach Ant how to use Hibernate's code generation tool -->
<taskdef name="hbm2java"
classname="org.hibernate.tool.ant.Hbm2JavaGeneratorTask"
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>

Regards,
Rob Wilson.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 15, 2005 6:24 pm 
Regular
Regular

Joined: Tue May 24, 2005 9:06 am
Posts: 64
Hibernate Extensions are related to Hibernate 2.x.

For Hibernate 3.1 you have to use Hibernate Tools with their own documentation (not included in the O'Reilly book). The documentation of Hibernate Extensions is not the right one for Hibernate Tools. BTW, the package names now start with "org.hibernate" and not with "net.sf".


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 16, 2005 5:28 am 
Newbie

Joined: Sat Oct 15, 2005 5:45 pm
Posts: 18
Thank you for your reply! In your opinion, would you say that I'm better sticking with Hibernate versions 2 to match the Oreilly book, or upgrade to version 3 and try to suss out all the differences as I am going?

For example, the section in the build

<!-- 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"/>

Would you be able to identify what the differences are for me? I changed the classname to match the new path, but I then had different errors (as per my original post). Any help would be appreciated.

Regards,
Rob Wilson.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 16, 2005 9:57 am 
Newbie

Joined: Sat Oct 15, 2005 5:45 pm
Posts: 18
As a test I have overwritten the JAR files in my lib directory with Hibernate version 2.1.8, also hibernate-extensions-2.1.3 to ensure that I can get things working with the older version of Hibernate. I've updated the build script to work with version 2 package structure names.

I'm sorry for the long post, but I have put as much information here as possible to see if someone can see what I have done wrong.

Unfortunately, I receive an error, as though some JAR is missing?:

Ideally I would like to know

1) What do I need to do, to get this working with Hibernate V2
2) What needs changing (once it's working) to get it working with Hibernate V3.

Please HELP!

C:\TS\Trunk\LearningZone\Hibernate>ant codegen
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.5.
0_04\lib\tools.jar
Buildfile: build.xml

codegen:
[hbm2java] Processing 1 mapping files.

BUILD FAILED
C:\TS\Trunk\LearningZone\Hibernate\build.xml:45: 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)


Total time: 2 seconds

The directories and files installed are summarised here:

Folder PATH listing
Volume serial number is 40D7-A32C
C:.
\Hibernate
| .classpath
| .project
| build.xml
| readme.txt
|
+---.settings
| org.eclipse.jdt.ui.prefs
|
+---data
| music.lck
| music.log
| music.properties
| music.script
|
+---lib
| ant-1.5.3.jar
| ant-1.6.5.jar
| ant-antlr-1.6.5.jar
| ant-junit-1.6.5.jar
| ant-launcher-1.6.5.jar
| ant-optional-1.5.3.jar
| ant-swing-1.6.5.jar
| antlr-2.7.5H3.jar
| asm-attrs.jar
| asm.jar
| bsh-2.0b1.jar
| c3p0-0.8.4.5.jar
| c3p0-0.9.0.jar
| cglib-2.1.2.jar
| cglib-full-2.0.2.jar
| cleanimports.jar
| commons-collections-2.1.1.jar
| commons-dbcp-1.2.1.jar
| commons-lang-1.0.1.jar
| commons-logging-1.0.4.jar
| commons-pool-1.2.jar
| concurrent-1.3.2.jar
| concurrent-1.3.3.jar
| connector.jar
| docking-0.3.2.jar
| dom4j-1.4.jar
| dom4j-1.6.1.jar
| ehcache-0.9.jar
| ehcache-1.1.jar
| forms-1.0.3.jar
| hibernate-tools.jar
| hibernateconsole.jar
| hsqldb.jar
| jaas.jar
| jacc-1_0-fr.jar
| jaxen-1.1-beta-7.jar
| jboss-cache.jar
| jboss-common.jar
| jboss-jmx.jar
| jboss-system.jar
| jcs-1.0-dev.jar
| jdbc2_0-stdext.jar
| jdom.jar
| jgraph-5.0.jar
| jgraphaddons.jar
| jgroups-2.2.7.jar
| jta.jar
| junit-3.8.1.jar
| l2fprod-common.jar
| log4j-1.2.11.jar
| log4j-1.2.8.jar
| looks-1.1.3.jar
| odmg-3.0.jar
| oscache-2.0.jar
| oscache-2.1.jar
| pf-joi-full.jar
| proxool-0.8.3.jar
| swarmcache-1.0rc2.jar
| velocity-1.3.1.jar
| versioncheck.jar
| xalan-2.4.0.jar
| xerces-2.4.0.jar
| xerces-2.6.2.jar
| xml-apis.jar
|
\---src
| hibernate.properties
| log4j.properties
|
\---com
\---oreilley
\---hh
Track.hbm.xml

BUILD.XML
=======
<?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>

<!-- classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask" -->
<!-- classname="org.hibernate.tool.ant.Hbm2JavaGeneratorTask" -->
<!-- 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">

<!-- classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask" -->
<!-- org.hibernate.tool.hbm2ddl.SchemaExportTask -->

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


TRACK.HBM.XML
===========
<?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>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 16, 2005 11:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
either use h2 with h2 tools or h3 with h3 tools - nuf said.

(p.s. and remember to include hibernate-x-y-z.jar when it complains about not being able to load hibernate classes ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 3:12 pm 
Newbie

Joined: Sat Oct 15, 2005 5:45 pm
Posts: 18
I've rolled back to version 2 and added the hibernate2.jar file - I can't beleive I missed that in the change!

It now works, so thank you very much.

For anyone else with issues, it's probably worth noting that I received some help from booktech@oreilly.com explaining about an errata that dealt with version issues.

Regards,
Rob.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.