I currently use the following tasks to create my database and build it's schema:
Code:
<target name="db-create" depends="define-tasks"
description="create database for ${database.type}">
<echo>Creating database with file: ${database.type}-create.sql</echo>
<sql
driver="${hibernate.connection.driver_class}"
url="${database.name}"
userid="${hibernate.connection.username}"
password="${hibernate.connection.password}">
<classpath refid="hibernate.classpath" />
<fileset dir="metadata/sql">
<include name="${database.type}-create.sql"/>
</fileset>
</sql>
</target>
<!-- =================================================================== -->
<!-- The "db-init" target generates the database schema and creates -->
<!-- tables based on the mapping files -->
<!-- =================================================================== -->
<target name="db-init" depends="clean,package-ejb"
description="creates database tables">
<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask">
<classpath>
<path refid="xdoclet.classpath" />
<path refid="hibernate.classpath" />
</classpath>
</taskdef>
<schemaexport quiet="no" text="no" drop="no"
properties="database.properties">
<fileset dir="${build.dir}/ejb/gen">
<include name="**/*.hbm.xml"/>
</fileset>
</schemaexport>
</target>
If ${database.type} is mysql, then it uses a mysql-create.sql file.
create database if not exists appfuse;
grant all privileges on appfuse.* to test@"%" identified by "test";
grant all privileges on appfuse.* to test@localhost identified by "test";
Rather than creating database scripts for all databases, it it possible for Hibernate to create the database (vs. maybe schemaexport task or SchemaExport class) for me?
Thanks,
Matt[/code]