I am generating the DDL from a series of classes containing JSR 220 annotations. I have successfully written the build.xml and hibernate.cfg.xml for this task. However, keeping up with each class to map within the cfg.xml file is tedious, especially with several different developers.
Is there any way to direct the schemaexport tool to generate the DDL for all classes, or for a set using wildcards?
I've attempted this using different attributes from the Hibernate 3.0 DTD "mapping" element to no avail. I also have tried dynamically generating a cfg.xml file, but have a chicken-and-egg problem (no DDL to generate from).
Any hints or insight appreciated. For completeness (and help for anyone else needing them), my cfg.xml and build.xml are given below.
hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="context">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.url">jdbc:mysql://SERVERNAME/mydatabase</property>
<property name="hibernate.connection.username">myusername</property>
<property name="hibernate.connection.password">mypassword</property>
<mapping class="p2p.common.security.Group"/>
<mapping class="p2p.common.security.Permission"/>
</session-factory>
</hibernate-configuration>
build.xml task
Code:
<target name="hibernate-mappings" description="Generates Hibernate class descriptor files." depends="properties">
<path id="path.hibernatetools">
<fileset dir="${dir.lib.hibernate.tools.plugin}\lib\tools" includes="hibernate-tools.jar" />
<fileset dir="${dir.lib.hibernate.tools.plugin}\lib\hibernate" includes="hibernate3.jar" />
<fileset dir="${dir.lib.hibernate.tools.plugin}\lib\hibernate" includes="commons-logging*.jar" />
<fileset dir="${dir.lib.hibernate.tools.plugin}\lib\annotations" includes="hibernate-annotations.jar" />
<fileset dir="${dir.lib.hibernate.tools.plugin}\lib\hibernate" includes="dom4j*.jar" />
<fileset dir="${dir.lib.hibernate.tools.plugin}\lib\annotations" includes="ejb3-persistence.jar" />
<fileset dir="${dir.lib.hibernate.tools.plugin}\lib\hibernate" includes="commons-collections*.jar" />
<!-- Include all database driver, cglib, and ehcache JARs -->
<fileset dir="${dir.lib.database.runtime}" includes="*.jar" />
<!-- Lastly, the Java JTA jar is required. -->
<fileset dir="${dir.lib.common}" includes="jta*.jar" />
</path>
<!-- Defines the hibernatedoclet task to be executed below. -->
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="path.hibernatetools" />
<hibernatetool destdir="${dir.source.sql}">
<classpath>
<path location="${dir.build}" />
</classpath>
<annotationconfiguration configurationfile="${basedir}/conf/local/hibernate.cfg.xml" />
<hbm2ddl outputfilename="hibernate.ddl.sql" drop="false" export="false" />
</hibernatetool>
</target>