Hi...
I can't 'get' the SchemaExport task to 'find' my class files, and as a result it (the task) bombs out with a 'cannot find persistent class Foo'.
The class files are generated as a part of my Ant build and stored in the 'build' directory... the SchemaExport task doesn't seem to allow a classpathref to be passed to it, or indeed to have a classpath reference nested within it. The'build' directory ain't on the system classpath, and I don't want it to be. The generated mapping files get stored in the build directory right next to their persistent mapped class.
I have a kludgey workaround (see below), which copies all of the mapping files into the root of the build directory, exports the schema, and then deletes all of those temporarily copied mapping files... it works, but it seems a tad bent.
I have, to the best of my knowledge, RTFM, but I can't get the plain vanilla ant task def to generate these mappings. It's not a total disaster (since the hack below works), but can anyone shed any light on this?
I'm using Hibernate 2.1.
Code:
<!--
Initializes the database relations using the previously generated Hibernate mapping
documents.
-->
<target name="db.generate-relations" description="Generates the database schema."
depends="db.generate-mappings">
<!--
Make some temporary copies of the mapping files.
-->
<copy todir="${build.home}">
<fileset dir="${build.home}" includes="**/*.hbm.xml" />
<mapper type="flatten"/>
</copy>
<echo message="Creating the database schema."/>
<java classname="net.sf.hibernate.tool.hbm2ddl.SchemaExport"
fork="true">
<jvmarg value="-Dhibernate.dialect=${db.dialect}"/>
<jvmarg value="-Dhibernate.connection.driver_class=${db.driver}"/>
<jvmarg value="-Dhibernate.connection.url=${db.url}${db.schema}"/>
<jvmarg value="-Dhibernate.connection.username=${db.user}"/>
<jvmarg value="-Dhibernate.connection.password=${db.password}"/>
<arg line="${basedir}/${build.home}/*.hbm.xml"/>
<classpath refid="build.classpath"/>
<classpath>
<pathelement location="${config.home}"/>
<pathelement location="${build.home}"/>
</classpath>
</java>
<!--
Clean up the temporary mapping files created previously.
-->
<delete>
<fileset dir="${build.home}" includes="*.hbm.xml"/>
</delete>
</target>