Hello, I'm trying to use the hbm2ddl tool in hibernate tools to generate a simple table in a HSQLDB database from my mapping file. The log indicates that the table is being created, but it's not. The "create table" SQL that hbm2ddl generates is valid (tested manually on the db).
After spending many hours on this problem, I am interested in any suggestions/pointers.
Thanks,
Jeff
Hibernate version:
Hibernate 3.0, Hibernate tools beta 3.8.1 beta1
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.oreilly.hh.Track" table="TRACK">
<meta attribute="class-description">
A single playable track.
</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" />
<property name="added" type="date" />
<property name="volume" type="short" />
</class>
</hibernate-mapping>
Ant build file:Code:
<?xml version="1.0"?>
<project name="Hibernate: a developer's notebook"
default="db" basedir=".">
<!-- properties -->
<!-- important directories -->
<property name="source.root" value="src" />
<property name="class.root" value="classes" />
<property name="lib.root" value="lib" />
<property name="data.root" value="data" />
<property name="ant.dir" value="c:\apache-ant-1.6.5" />
<property name="hibernate.tools.dir"
value="C:\Hibernate_tools_3_1_0_beta1\plugins\org.hibernate.eclipse_3.1.0.beta1" />
<property name="hsqldb.dir" value="c:\hsqldb" />
<!-- Set up the classpath for compilation and execution -->
<path id="project.class.path">
<pathelement location="${class.root}" />
<!-- jars -->
<fileset dir="${lib.root}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${ant.dir}/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="${hibernate.tools.dir}/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="${hsqldb.dir}/lib">
<include name="**/*.jar" />
</fileset>
</path>
<!-- /////////////////////////////////////////////////////////////// -->
<!-- HSQLDB -->
<target name="db" description="Run HSQLDB db management tool -- use
when app isn't 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.root}/music" />
<arg value="-user" />
<arg value="sa" />
</java>
</target>
<!-- /////////////////////////////////////////////////////////////// -->
<!-- Java code generation from .hbm.xml -->
<!-- generate Java code for all mapping files in source -->
<target name="codegen" description="Generate Java code from O/R
mapping files.">
<!-- teach Ant how to use code generation tool -->
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathRef="project.class.path" />
<hibernatetool destdir="${source.root}">
<configuration propertyFile="${source.root}/hibernate.properties">
<fileset dir="${source.root}">
<include name="**/*.hbm.xml" />
</fileset>
</configuration>
<hbm2java/>
</hibernatetool>
</target>
<!-- /////////////////////////////////////////////////////////////// -->
<!-- create runtime directories and copy resources -->
<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>
<!-- /////////////////////////////////////////////////////////////// -->
<!-- compile java code -->
<target name="compile" depends="prepare" description="compiles all">
<javac srcdir="${source.root}" destdir="${class.root}" debug="on"
optimize="off" deprecation="on">
<classpath refid="project.class.path" />
</javac>
</target>
<!-- /////////////////////////////////////////////////////////////// -->
<!-- Generate schemae for all mapping files -->
<!-- Reference: http://www.hibernate.org/hib_docs/tools/ant/ -->
<target name="schema" depends="compile" description="gens db schema">
<!-- teach Ant how to use code generation tool -->
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathRef="project.class.path" />
<!-- hibernate tool task has already been defined. -->
<hibernatetool destdir="${data.root}">
<configuration propertyFile="${class.root}/hibernate.properties" >
<fileset dir="${class.root}">
<include name="**/*.hbm.xml" />
</fileset>
</configuration>
<hbm2ddl drop="no" create="yes" />
</hibernatetool>
</target>
</project>
Code between sessionFactory.openSession() and session.close():n/a
Full stack trace of any exception that occurs:n/a
Name and version of the database you are using:HSQL database engine, version 1.8.0
(runs fine)
The generated SQL (show_sql=true):n/a --- see the log excerpt
Debug level Hibernate log excerpt:Code:
Buildfile: build.xml
prepare:
[copy] Copying 1 file to C:\Documents and Settings\Jeff Zohrab\My Documents\hibernate_developers_notebook\classes
compile:
schema:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] 22:57:55,001 INFO Environment:474 - Hibernate 3.1 rc1
[hibernatetool] 22:57:55,051 INFO Environment:489 - loaded properties from resource hibernate.properties: {hibernate.connection.username=sa, hibernate.connection.autocommit=true, hibernate.connection.password=****, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=org.hibernate.dialect.HSQLDialect, hibernate.connection.url=jdbc:hsqldb:data/music, hibernate.connection.driver_class=org.hsqldb.jdbcDriver}
[hibernatetool] 22:57:55,061 INFO Environment:520 - using CGLIB reflection optimizer
[hibernatetool] 22:57:55,061 INFO Environment:550 - using JDK 1.4 java.sql.Timestamp handling
[hibernatetool] 22:57:55,772 INFO Configuration:258 - Reading mappings from file: C:\Documents and Settings\Jeff Zohrab\My Documents\hibernate_developers_notebook\classes\com\oreilly\hh\Track.hbm.xml
[hibernatetool] 22:57:56,232 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd in classpath under org/hibernate/
[hibernatetool] 22:57:56,242 DEBUG DTDEntityResolver:56 - found http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd in classpath
[hibernatetool] 22:57:57,144 INFO HbmBinder:266 - Mapping class: com.oreilly.hh.Track -> TRACK
[hibernatetool] 22:57:57,194 DEBUG HbmBinder:1179 - Mapped property: id -> TRACK_ID
[hibernatetool] 22:57:57,314 DEBUG HbmBinder:1179 - Mapped property: title -> title
[hibernatetool] 22:57:57,324 DEBUG HbmBinder:1179 - Mapped property: filePath -> filePath
[hibernatetool] 22:57:57,324 DEBUG HbmBinder:1179 - Mapped property: playTime -> playTime
[hibernatetool] 22:57:57,324 DEBUG HbmBinder:1179 - Mapped property: added -> added
[hibernatetool] 22:57:57,344 DEBUG HbmBinder:1179 - Mapped property: volume -> volume
[hibernatetool] 22:57:57,344 INFO Configuration:1014 - processing extends queue
[hibernatetool] 22:57:57,354 INFO Configuration:1018 - processing collection mappings
[hibernatetool] 22:57:57,354 INFO Configuration:1027 - processing association property references
[hibernatetool] 22:57:57,354 INFO Configuration:1049 - processing foreign key constraints
[hibernatetool] 22:57:57,584 INFO Dialect:100 - Using dialect: org.hibernate.dialect.HSQLDialect
[hibernatetool] 22:57:58,195 INFO Configuration:1014 - processing extends queue
[hibernatetool] 22:57:58,195 INFO Configuration:1018 - processing collection mappings
[hibernatetool] 22:57:58,195 INFO Configuration:1027 - processing association property references
[hibernatetool] 22:57:58,205 INFO Configuration:1049 - processing foreign key constraints
[hibernatetool] 22:57:58,686 INFO Configuration:1014 - processing extends queue
[hibernatetool] 22:57:58,696 INFO Configuration:1018 - processing collection mappings
[hibernatetool] 22:57:58,696 INFO Configuration:1027 - processing association property references
[hibernatetool] 22:57:58,706 INFO Configuration:1049 - processing foreign key constraints
[hibernatetool] 22:57:58,736 INFO SchemaExport:153 - Running hbm2ddl schema export
[hibernatetool] 22:57:58,776 DEBUG SchemaExport:171 - import file not found: /import.sql
[hibernatetool] 22:57:58,776 INFO SchemaExport:180 - exporting generated schema to database
[hibernatetool] 22:57:58,806 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
[hibernatetool] 22:57:58,816 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
[hibernatetool] 22:57:58,816 INFO DriverManagerConnectionProvider:45 - autocommit mode: true
[hibernatetool] 22:57:58,826 INFO DriverManagerConnectionProvider:80 - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:data/music
[hibernatetool] 22:57:58,836 INFO DriverManagerConnectionProvider:83 - connection properties: {user=sa, password=, autocommit=true}
[hibernatetool] 22:57:58,856 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
[hibernatetool] 22:57:58,866 DEBUG DriverManagerConnectionProvider:109 - opening new JDBC connection
[hibernatetool] 22:58:00,849 DEBUG DriverManagerConnectionProvider:115 - created connection to: jdbc:hsqldb:data/music, Isolation Level: 0
[hibernatetool] drop table TRACK if exists;
[hibernatetool] 22:58:00,869 DEBUG SchemaExport:283 - drop table TRACK if exists;
[hibernatetool] 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, primary key (TRACK_ID));
[hibernatetool] 22:58:00,869 DEBUG SchemaExport:283 - 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, primary key (TRACK_ID));
[hibernatetool] 22:58:00,919 INFO SchemaExport:200 - schema export complete
[hibernatetool] 22:58:00,939 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
[hibernatetool] 22:58:00,939 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:hsqldb:data/music
BUILD SUCCESSFUL
Total time: 10 seconds
[/b]