-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Schema export: Table is not generated in HSQLDB database
PostPosted: Tue Mar 29, 2005 9:33 am 
Newbie

Joined: Tue Mar 29, 2005 5:52 am
Posts: 7
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?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 30, 2005 3:40 am 
Newbie

Joined: Tue Mar 29, 2005 5:52 am
Posts: 7
I noticed that the schema export does not issue a commit statement. Is there an autocommit setting somewhere, or another way to get hibernate to tell the DB to commit after exporting the schema?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 30, 2005 4:19 am 
Newbie

Joined: Tue Mar 29, 2005 5:52 am
Posts: 7
I checked the code in SchemaExport.java, and it calls setAutoCommit() on the connection if getAcoutCommit() returns false, so autocommit should be on...


Top
 Profile  
 
 Post subject: What?
PostPosted: Fri May 27, 2005 9:37 am 
Newbie

Joined: Fri May 27, 2005 7:37 am
Posts: 6
Where is SchemaExport.java ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 27, 2005 10:30 am 
Newbie

Joined: Tue Mar 29, 2005 5:52 am
Posts: 7
SchemaExport is in the org.hibernate.tool.hbm2ddl package.

Regarding your question here: http://forum.hibernate.org/viewtopic.ph ... 50#2244050 - sorry, no, never figured it out (now i'm using MySQL on a different porject, where it works).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 03, 2005 2:54 pm 
Newbie

Joined: Wed Nov 19, 2003 3:00 am
Posts: 7
Location: Madison, Wisconsin, USA
This is probably due to a change in Hypersonic's behavior starting with version 1.7.2. In a nutshell, old versions would automatically shut down the database as soon as there were no more connections to it. The new versions don't shut down unless given an explicit shutdown command, and hbm2ddl does not issue that shutdown command, so Hypersonic never flushes the changes to disk before the JVM gets shut down. Hence, your schema is never written to disk.

If you are using Hypersonic 1.8 or later you can work around this by requesting the old automatic shutdown behavior. Hibernate will enable this if you define hibernate.connection.shutdown=true in your properties or XML file.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 11:23 pm 
Newbie

Joined: Mon Nov 21, 2005 11:18 pm
Posts: 6
This last post by 'brunchboy' worked like a charm. For those of you not using a hibernate.properties file and are specifying connection information along with all your mapping files in a .cfg.xml file you'll want to add the following property like this...

<property name="hibernate.connection.shutdown">true</property>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.