Version 2

    Since Hibernate 3.1 you can/should use the following ant tasks:

        <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath.schema"/>
    
        <target name="schema-drop" depends="compile">
            <hibernatetool destdir="">
                <configuration configurationfile="${generated}/hibernate.cfg.xml" />
                <hbm2ddl drop="true" create="false" export="true" update="false"/>
            </hibernatetool>
        </target>
        <target name="schema-recreate" depends="compile">
            <hibernatetool destdir="">
                <configuration configurationfile="${generated}/hibernate.cfg.xml" />
                <hbm2ddl drop="true" create="true" export="true" update="false"/>
            </hibernatetool>
        </target>
    
        <target name="schema-docu" depends="compile" description="Generate a html description of the mappings">
            <hibernatetool destdir="hibernate-html">
                <configuration configurationfile="${generated}/hibernate.cfg.xml" />
                <hbm2doc/>
            </hibernatetool>
        </target>

     

    The required classes are contained in a separate jar that is part of the Hibernate tools plugin for Eclipse.

    Also note that since Hibernate 3.1 you can include a file called "import.sql" in the runtime classpath of Hibernate. At the time of schema export it will execute the SQL statements contained in that file after the schema has been exported.

     

    One problem that exists at least until 3.1.2 is that if you have any "error" in your custom sqls the generation will fail. This makes it impossible to safely drop sequences or indexes before you create them in that file. That is because either you only "create" your stuff which will fail the second time or you "drop" and "create" which will fail the first time since there is nothing to drop.