• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem at using hibernate extension to build *java from *.hbm.xml

Jianfeng Qian
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i sui \
this is a n example fo Hibernate: A Developer's Notebook
I use hibernate 2.1,hibernate extension 2.1 to build *.hbm.xml

my Track.hbm.xml is as followed
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"


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

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

<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 name="added" type="date">
<meta attribute="field-description">When the track was created</meta>

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


my build.xml is as followed
<?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"/>

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

<!-- Teach Ant how to use Hibernate's code generation tool -->
<taskdef name="hbm2java"

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

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

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

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

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


D:\java\hproject>ant codegen
Buildfile: build.xml

[hbm2java] Processing 1 files.
[hbm2java] Building hibernate objects
[hbm2java] log4j:WARN No appenders could be found for logger (net.sf.hibernate.util.DTDEntityResolv
[hbm2java] log4j:WARN Please initialize the log4j system properly.
[hbm2java] java.lang.NullPointerException
[hbm2java] at net.sf.hibernate.tool.hbm2java.BasicRenderer.isPropertySet(BasicRenderer.java:611
[hbm2java] at net.sf.hibernate.tool.hbm2java.BasicRenderer.generateConcreteEmptyClasses(BasicRe
[hbm2java] at net.sf.hibernate.tool.hbm2java.BasicRenderer.render(BasicRenderer.java:59)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Generator.write(Generator.java:138)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Generator.writeRecur(Generator.java:115)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Generator.generate(Generator.java:104)
[hbm2java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:125)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.java:145)
[hbm2java] at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java:95)
[hbm2java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[hbm2java] at org.apache.tools.ant.Task.perform(Task.java:364)
[hbm2java] at org.apache.tools.ant.Target.execute(Target.java:341)
[hbm2java] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[hbm2java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
[hbm2java] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
[hbm2java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:4
[hbm2java] at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
[hbm2java] at org.apache.tools.ant.Main.runBuild(Main.java:668)
[hbm2java] at org.apache.tools.ant.Main.startAnt(Main.java:187)
[hbm2java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
[hbm2java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Christophe Verré
Posts: 14691
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check the Errata page of this book. (Search for "AUTHOR NOTE")

Try to download the latest source from O'Reilly's homepage.
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!