Hibernate JPA for DDL Command Line Tools

There are Hibernate tools for matching files with ddl generation; ddl for file matching, etc., but I can not find any command line tools to easily generate DDL from annotated JPA classes.

Does anyone know an easy way to do this? (Do not use Ant or Maven workarounds)

+5
source share
2 answers

I am not sure if this is considered a workaround because you already mentioned this in your question. You can use Hibernate Tools to create DDL from annotated JPA classes. You just need tools for hibernation and its dependency on the class path, and should be fine with something like the following:

<target name="schemaexport" description="Export schema to DDL file"
    depends="compile-jpa"> <!-- compile model classes before running hibernatetool -->

  <!-- task definition; project.class.path contains all necessary libs -->
  <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
      classpathref="project.class.path" />

  <hibernatetool destdir="export/db"> <!-- check that directory exists -->
    <jpaconfiguration persistenceunit="myPersistenceUnitName" />
    <classpath>
      <!--
          compiled model classes and other configuration files don't forget
          to put the parent directory of META-INF/persistence.xml here
      -->
    </classpath>
    <hbm2ddl outputfilename="schemaexport.sql" format="true"
        export="false" drop="true" />
  </hibernatetool>
</target>

On the other hand, if you use Eclipse with Webtools and configure the project settings correctly, you can simply right-click and select “Create DDL” from the context menu. More information about him can be found on the Eclipse Dali website .

+7
source
+4

All Articles