Hibernate JPA到DDL命令行工具

Ver*_*ant 5 hibernate jpa

有用于将文件映射到ddl生成的Hibernate工具; ddl到映射文件等等,但我找不到任何命令行工具,可以从JPA注释类生成简单的DDL.

有谁知道一个简单的方法来做到这一点?(不使用Ant或Maven解决方法)

Kar*_*iem 7

我不确定,这是否被认为是一种解决方法,因为你已经在你的问题中提到了它.您可以使用Hibernate Tools从JPA注释类生成DDL.您只需要在类路径上使用hibernate工具及其依赖项,并且应该可以使用以下内容:

<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>
Run Code Online (Sandbox Code Playgroud)

另一方面,如果您将Eclipse与Webtools一起使用并且已正确配置项目设置,则可以右键单击并从上下文菜单中选择Generate DDL.有关Eclipse Dali网站上有关该信息的更多信息.