I've been trying to run the schemaexport task for Listing 2.9 of Java Persistence with Hibernate on P65.
I'm struggling to understand why this class is not found.
If I'm reading the Ant script correctly, the taskdef for hibernatetool has a classpathref of project.classpath. This includes all the jars in my lib folder.
Which includes dom4j-1.6.1.jar.
This jar does have the class org/dom4j/io/OutputFormat!
So why is it not found?
Here is the build.xml:
Code:
<project name="HelloWorld" default="compile" basedir=".">
<!-- Name of project and version -->
<property name="proj.name" value="HelloWorld" />
<property name="proj.version" value="1.0"/>
<!-- Global properties for this build -->
<property name="src.java.dir" value="src"/>
<property name="lib.dir" value="lib"/>
<property name="build.dir" value="bin"/>
<!-- Classpath declaration -->
<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
<include name="**/*.zip"/>
</fileset>
</path>
<!-- Useful shortcuts -->
<patternset id="meta.files">
<include name="**/*.xml"/>
<include name="**/*.properties"/>
</patternset>
<!-- Clean up -->
<target name="clean">
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
</target>
<!-- Compile Java source -->
<target name="compile" depends="clean">
<javac
srcdir="${src.java.dir}"
destdir="${build.dir}"
nowarn="on">
<classpath refid="project.classpath"/>
</javac>
</target>
<!-- Copy metadata to build classpath -->
<target name="copymetafiles">
<copy todir="${build.dir}">
<fileset dir="${src.java.dir}">
<patternset refid="meta.files"/>
</fileset>
</copy>
</target>
<!-- Run HelloWorld -->
<target name="run" depends="compile, copymetafiles"
description="Build and run HelloWorld">
<java fork="true"
classname="hello.HelloWorld"
classpathref="project.classpath">
<classpath path="${build.dir}"/>
</java>
</target>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="project.classpath"/>
<target name="schemaexport" depends="compile, copymetafiles"
description="Exports a generated schema to DB and file">
<hibernatetool destdir="${basedir}">
<classpath path="${build.dir}"/>
<configuration
configurationfile="${build.dir}/hibernate.cfg.xml" />
<hbm2ddl
drop="true"
create="true"
export="true"
outputfilename="helloworld-ddl.sql"
delimiter=";"
format="true"/>
</hibernatetool>
</target>
</project>
Here is directory output that shows all versions etc:
Code:
16/05/2008 21:35 <DIR> .
16/05/2008 21:35 <DIR> ..
16/05/2008 21:07 <DIR> bin
16/05/2008 20:04 2,316 build.xml
16/05/2008 21:35 0 dir.txt
16/05/2008 19:47 <DIR> hsql
16/05/2008 21:06 <DIR> lib
16/05/2008 17:59 <DIR> src
16/05/2008 19:51 16 test.lck
16/05/2008 19:51 34 test.log
16/05/2008 19:51 436 test.properties
5 File(s) 2,802 bytes
Directory of C:\Book Downloads\Java Persistence with Hibernate\helloworld\bin
16/05/2008 21:07 <DIR> .
16/05/2008 21:07 <DIR> ..
16/05/2008 21:07 <DIR> hello
16/05/2008 21:07 1,302 hibernate.cfg.xml
16/05/2008 21:07 419 hibernate.properties
16/05/2008 21:07 507 log4j.properties
16/05/2008 21:07 <DIR> persistence
3 File(s) 2,228 bytes
Directory of C:\Book Downloads\Java Persistence with Hibernate\helloworld\bin\hello
16/05/2008 21:07 <DIR> .
16/05/2008 21:07 <DIR> ..
16/05/2008 21:07 1,983 HelloWorld.class
16/05/2008 21:07 692 Message.class
16/05/2008 21:07 564 Message.hbm.xml
3 File(s) 3,239 bytes
Directory of C:\Book Downloads\Java Persistence with Hibernate\helloworld\bin\persistence
16/05/2008 21:07 <DIR> .
16/05/2008 21:07 <DIR> ..
16/05/2008 21:07 737 HibernateUtil.class
1 File(s) 737 bytes
Directory of C:\Book Downloads\Java Persistence with Hibernate\helloworld\hsql
16/05/2008 19:47 <DIR> .
16/05/2008 19:47 <DIR> ..
16/05/2008 19:47 16 localhost.lck
16/05/2008 19:47 34 localhost.log
16/05/2008 19:47 436 localhost.properties
3 File(s) 486 bytes
Directory of C:\Book Downloads\Java Persistence with Hibernate\helloworld\lib
16/05/2008 21:06 <DIR> .
16/05/2008 21:06 <DIR> ..
05/05/2006 11:58 443,432 antlr-2.7.6.jar
17/03/2005 16:05 16,777 asm-attrs.jar
17/03/2005 15:32 26,360 asm.jar
19/01/2007 09:04 608,376 c3p0-0.9.1.jar
02/12/2005 11:28 282,338 cglib-2.1.3.jar
30/06/2004 04:59 175,426 commons-collections-2.1.1.jar
04/07/2004 04:49 38,015 commons-logging-1.0.4.jar
13/08/2005 15:28 313,898 dom4j-1.6.1.jar
03/12/2007 14:54 349,357 hibernate-tools.jar
06/02/2008 21:31 2,274,768 hibernate3.jar
01/11/2007 19:47 699,936 hsqldb.jar
03/06/2004 11:31 8,812 jta.jar
13/08/2005 15:28 350,627 log4j-1.2.11.jar
13 File(s) 5,588,122 bytes
Directory of C:\Book Downloads\Java Persistence with Hibernate\helloworld\src
16/05/2008 17:59 <DIR> .
16/05/2008 17:59 <DIR> ..
16/05/2008 16:43 <DIR> hello
16/05/2008 20:55 1,302 hibernate.cfg.xml
16/05/2008 17:43 419 hibernate.properties
16/05/2008 18:06 507 log4j.properties
16/05/2008 17:47 <DIR> persistence
3 File(s) 2,228 bytes
Directory of C:\Book Downloads\Java Persistence with Hibernate\helloworld\src\hello
16/05/2008 16:43 <DIR> .
16/05/2008 16:43 <DIR> ..
16/05/2008 18:33 1,639 HelloWorld.java
16/05/2008 16:40 564 Message.hbm.xml
16/05/2008 18:34 594 Message.java
3 File(s) 2,797 bytes
Directory of C:\Book Downloads\Java Persistence with Hibernate\helloworld\src\persistence
16/05/2008 17:47 <DIR> .
16/05/2008 17:47 <DIR> ..
16/05/2008 18:37 624 HibernateUtil.java
1 File(s) 624 bytes
Here is log4j properties:
Code:
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Root logger option
log4j.rootLogger=info, stdout
# Hibernate logging options (INFO only show startup messages)
log4j.logger.org.hibernate=info
# Log JDBC bind parameter runtime arguments
log4j.logger.org.hibernate.type=info
I did notice in etc folder message types (INFO) were always in lower case. Tried this change. And still have same problem..
Here is hibernate.cfg.xml:
Code:
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
org.hsqldb.jdbcDriver
</property>
<property name="hibernate.connection.url">
jdbc:hsqldb:hsql://localhost
</property>
<property name="hibernate.connection.username">
sa
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.HSQLDialect
</property>
<!-- Use the C3P0 connection pool provider -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">5</property>
<!-- Show and print nice SQL on stdout
Dynamic system properties is possible
${displaysql}
Command line: java -displaysql=true -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<!-- List of XML mapping files -->
<mapping resource="hello/Message.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Here is Message.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="hello.Message"
table="MESSAGES">
<id
name="id"
column="MESSAGE_ID">
<generator class="increment"/>
</id>
<property
name="text"
column="MESSAGE_TEXT"/>
<many-to-one
name="nextMessage"
cascade="all"
column="NEXT_MESSAGE_ID"
foreign-key="FK_NEXT_MESSAGE"/>
</class>
</hibernate-mapping>