Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • 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"
"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>

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

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

codegen:
[hbm2java] Processing 1 files.
[hbm2java] Building hibernate objects
[hbm2java] log4j:WARN No appenders could be found for logger (net.sf.hibernate.util.DTDEntityResolv
er).
[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
nderer.java:332)
[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
0)
[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é
Sheriff
Posts: 14691
16
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic