This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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

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}/"
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(
[hbm2java] at net.sf.hibernate.tool.hbm2java.BasicRenderer.generateConcreteEmptyClasses(BasicRe
[hbm2java] at net.sf.hibernate.tool.hbm2java.BasicRenderer.render(
[hbm2java] at net.sf.hibernate.tool.hbm2java.Generator.write(
[hbm2java] at net.sf.hibernate.tool.hbm2java.Generator.writeRecur(
[hbm2java] at net.sf.hibernate.tool.hbm2java.Generator.generate(
[hbm2java] at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(
[hbm2java] at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(
[hbm2java] at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.execute(
[hbm2java] at
[hbm2java] at
[hbm2java] at
[hbm2java] at
[hbm2java] at
[hbm2java] at
[hbm2java] at
[hbm2java] at
[hbm2java] at
[hbm2java] at
[hbm2java] at
[hbm2java] at
Posts: 14691
Eclipse IDE VI Editor Ubuntu
  • 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.
Acetylsalicylic acid is aspirin. This could be handy too:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!