Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
I am trying to run an example from the Hibernate Developer's Notebook. I can run the code below and type in ant schema. It looks like it's running fine, until I run ant db again and there are no tables and there is also no code in the .sql file it's created. Can anyone help me get past this error?
Thanks in advance,
Hibernate version:
2.1.7c since that was recommended by the book
Build document:
<?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 HSWLDB database management UI against the db 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" depends="prepare" 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" output="schema.sql" quiet="false" text="yes" drop="yes" delimiter=";">
<fileset dir="${class.root}">
<include name="**.*.hbm.xml"/>
</fileset>
</schemaexport>
</target>
</project>
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">
<meta attribute="field-description">How loud to play the track</meta>
</property>
</class>
</hibernate-mapping>
hibernate.properties file:
hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:hsqldb:data/music
hibernate.connection.username=sa
hibernate.connection.password=
Full stack trace of any exception that occurs:
R:\soa\bin\Hibernate2.1.7\hibernate-2.1.7c\hibernate-2.1\Project>ant schema
Buildfile: build.xml
prepare:
compile:
schema:
[schemaexport] 10:51:54,027 INFO Environment:478 - Hibernate 2.1.7
[schemaexport] 10:51:54,230 INFO Environment:512 - loaded properties from resou
rce hibernate.properties: {hibernate.connection.username=sa, hibernate.connectio
n.password=, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=ne
t.sf.hibernate.dialect.HSQLDialect, hibernate.connection.url=jdbc:hsqldb:data/mu
sic, hibernate.connection.driver_class=org.hsqldb.jdbcDriver}
[schemaexport] 10:51:54,293 INFO Environment:538 - using CGLIB reflection optim
izer
[schemaexport] 10:51:54,293 INFO Environment:567 - using JDK 1.4 java.sql.Times
tamp handling
[schemaexport] 10:51:55,996 INFO Dialect:86 - Using dialect: net.sf.hibernate.d
ialect.HSQLDialect
[schemaexport] 10:51:58,261 INFO Configuration:632 - processing one-to-many ass
ociation mappings
[schemaexport] 10:51:58,277 INFO Configuration:641 - processing one-to-one asso
ciation property references
[schemaexport] 10:51:58,277 INFO Configuration:666 - processing foreign key con
straints
[schemaexport] 10:51:58,277 INFO Configuration:632 - processing one-to-many ass
ociation mappings
[schemaexport] 10:51:58,277 INFO Configuration:641 - processing one-to-one asso
ciation property references
[schemaexport] 10:51:58,277 INFO Configuration:666 - processing foreign key con
straints
[schemaexport] 10:51:58,293 INFO SchemaExport:98 - Running hbm2ddl schema expor
t
[schemaexport] 10:51:58,293 INFO SchemaExport:112 - writing generated schema to
file: schema.sql
[schemaexport] 10:51:58,293 INFO SchemaExport:160 - schema export complete
BUILD SUCCESSFUL
Total time: 14 seconds
Name and version of the database you are using:
HSQLDB 1.7.1
The generated SQL (show_sql=true): .
It's not generating SQL in the .sql file it's creating or showing up on the console
Debug level Hibernate log excerpt: