Hibernate JPA到DDL命令行工具 [英] Hibernate JPA to DDL command line tools

查看:172
本文介绍了Hibernate JPA到DDL命令行工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

解决方案

我不确定,这是否被认为是解决方法,因为您已经提到在你的问题中。您可以使用 Hibernate工具从JPA注释类生成DDL。您只需要hibernate工具及其对类路径的依赖关系,并且应该如下所示:

 < target name = schemaexportdescription =将模式导出到DDL文件
depends =compile-jpa> <! - 在运行hibernatetool之前编译模型类 - >

<! - 任务定义; project.class.path包含所有必需的库 - >
< taskdef name =hibernatetoolclassname =org.hibernate.tool.ant.HibernateToolTask​​
classpathref =project.class.path/>

< hibernatetool destdir =export / db> <! - 检查该目录是否存在 - >
< jpaconfiguration persistenceunit =myPersistenceUnitName/>
< classpath>
<! -
编译模型类和其他配置文件不要忘记
将META-INF / persistence.xml的父目录放在这里
- >
< / classpath>
export =falsedrop =true/>
< / hibernatetool>
< / target>另一方面,如果您使用带有Webtools的Eclipse并且正确配置了项目设置,那么您可以使用以下命令来设置项目设置:

可以右键单击并从上下文菜单中选择生成DDL 。有关 Eclipse Dali网站的更多信息。


There are Hibernate tools for mapping files to ddl generation; ddl to mapping files and so on, but I can't find any command line tools for simple DDL generation from JPA annotated classes.

Does anyone know an easy way to do this? (Not using Ant or Maven workarounds)

解决方案

I'm not sure, whether this is considered a workaround, because you already referred to it in your question. You can use Hibernate Tools to generate DDL from JPA annotated classes. You just need hibernate tools and its dependencies on the classpath 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 are using Eclipse with Webtools and have configured the project settings correctly, you can just right click and select Generate DDL from the context menu. More information about that on the Eclipse Dali website.

这篇关于Hibernate JPA到DDL命令行工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆