Using hbm2ddl when model and EM are in different projects

190 views Asked by At

I have a locally-created jar file containing hibernate-annotated entities. I also have a separate project which references this jar.

I need to create a db script using hbm2ddl, but am encounting some difficulty. When I try to use the task in the jar file's build.xml, the persistence unit can't be found. When I try to use the task in the war file's build.xml, no entities are found at all.

This has to be something that's being done by others -- how do you create the SQL when the entities and EM are in different Eclipse projects built by separate build scripts?

1

There are 1 answers

0
Bret On BEST ANSWER

The trick here was including the jar file in the classpath of the task which includes hbm2ddl:

<target name="schemaexport" depends="compile">
    <hibernatetool destdir="${basedir}/sql">
        <classpath>
            <fileset dir="${lib.dir}">
                <include name="common.jar" />
            </fileset>
        </classpath>
        <jpaconfiguration />
        <hbm2ddl export="false" create="true" drop="true" delimiter=";" format="true" outputfilename="${project.name}-ddl.sql" />
    </hibernatetool>
</target>