Hi. I'm going through the example in chapter 2 in
Harnessing Hibernate. It basically uses the SchemaExportTask ant task to create a single table in a HSQLDB database.
My problem is that the table is not actually created in the DB. The .script file where HSQLDB stores its data does not contain the table ddl after the build script is run.
Build script:
Code:
<?xml version="1.0"?>
<project name="Harnessing Hibernate" default="db" basedir=".">
<property name="source.root" value="src" />
<property name="class.root" value="output/classes" />
<property name="lib.dir" value="lib" />
<property name="data.dir" value="data" />
<path id="project.class.path">
<pathelement location="${class.root}" />
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="db" description="Runs HSQLDB database management UI against DB file.">
<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>
<taskdef name="hbm2java" classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask" classpathref="project.class.path"/>
<target name="prepare" description="Sets up build structures">
<mkdir dir="${class.root}" />
<copy todir="${class.root}">
<fileset dir="${source.root}">
<include name="**/*.properties" />
<include name="**/*.hbm.xml" />
</fileset>
</copy>
</target>
<target name="codegen" depends="prepare" description="Generate Java source form mapping files">
<hbm2java output="${source.root}">
<fileset dir="${source.root}">
<include name="**/*.hbm.xml" />
</fileset>
</hbm2java>
</target>
<target name="compile" depends="prepare">
<javac
srcdir="${source.root}"
destdir="${class.root}"
debug="on"
optimize="off"
deprecation="on">
<classpath refid="project.class.path" />
</javac>
</target>
<target name="schema" depends="compile" description="Generate DB schema from the O/R mapping files">
<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>
Output from running ant schema:
Code:
build.xml
property
property
property
property
path
taskdef
prepare
mkdir
copy
Copying 1 file to C:\projects\hh\output\classes
compile
javac
schema
taskdef
schemaexport
29.mar.2005 15:12:59 net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.8
29.mar.2005 15:12:59 net.sf.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.username=sa, hibernate.connection.password=, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect, hibernate.connection.url=jdbc:hsqldb:data/music, hibernate.connection.driver_class=org.hsqldb.jdbcDriver}
29.mar.2005 15:12:59 net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
29.mar.2005 15:12:59 net.sf.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
29.mar.2005 15:12:59 net.sf.hibernate.cfg.Configuration addFile
INFO: Mapping file: C:\projects\hh\output\classes\com\oreilly\hh\Track.hbm.xml
29.mar.2005 15:13:00 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: com.oreilly.hh.Track -> TRACK
29.mar.2005 15:13:00 net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.HSQLDialect
29.mar.2005 15:13:00 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
29.mar.2005 15:13:00 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
29.mar.2005 15:13:00 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
29.mar.2005 15:13:00 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
29.mar.2005 15:13:00 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
29.mar.2005 15:13:00 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
29.mar.2005 15:13:00 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: Running hbm2ddl schema export
29.mar.2005 15:13:00 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
29.mar.2005 15:13:00 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
29.mar.2005 15:13:00 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
29.mar.2005 15:13:00 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:data/music
29.mar.2005 15:13:00 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=sa, password=}
drop table TRACK if exists
create table TRACK (
TRACK_ID integer generated by default as identity (start with 1),
title varchar(255) not null,
filePath varchar(255) not null,
playTime time,
added date,
volume smallint
)
29.mar.2005 15:13:01 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete
29.mar.2005 15:13:01 net.sf.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:hsqldb:data/music
Ant build completed with 42 warnings at 15:13:01 in 3s
Hibernate version:2.1.8
Mapping documents:One, Track.xml.hbm:
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"C:\Documents and Settings\extari\.IntelliJIdea\system\extResources\f02c51ff_hibernate-mapping-3.0.dtd.xml">
<!-- DTD location is local to prevent the validator from attempting to connect to the original DTD URL -->
<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 Elliot (typed by André!)
</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 load to play the track</meta>
</property>
</class>
</hibernate-mapping>
Name and version of the database you are using:HSQLDB 1.0.8
The generated SQL (show_sql=true):Copied from the ant output above:
Code:
drop table TRACK if exists
create table TRACK (
TRACK_ID integer generated by default as identity (start with 1),
title varchar(255) not null,
filePath varchar(255) not null,
playTime time,
added date,
volume smallint
)
This SQL code works fine in the HSQL database manager. The class file for the java file generated from the mapping file compiles without error. What am i doing wrong?