使用EclipseLink为JPA 2.0生成DDL [英] Generate DDL for JPA 2.0 with EclipseLink

查看:257
本文介绍了使用EclipseLink为JPA 2.0生成DDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用JPA 2.0注释创建了模型类.在运行时,我将使用EclipseLink 2.2.0,但在模型类中我只使用纯JPA注释.

I've created my model classes with JPA 2.0 annotations. At runtime, I will use EclipseLink 2.2.0, but I've been careful to use only pure JPA annotations in my model classes.

现在,如何为数据库生成模式DDL?

Now, how do I generate the schema DDL for the database ?

我想使用EclipseLink API从类中生成DDL,但不是在运行时.相反,我希望Java类在命令行上运行并输出DDL. 这个人为休眠做的事情,我想要EclipseLink.

I want to use the EclipseLink API to generate the DDL from the classes, but not at runtime. Instead, I want a Java class to run on the command line and which outputs the DDL. What this guy did for Hibernate, I want for EclipseLink.

我还要为Ant任务或Maven的一些插件做好准备.

I'd also settle for an Ant task or some plugin for Maven.

此外,我选择将文件命名为 jpa.xml 而不是 persistence.xml ;奖励积分(如果您的解决方案也考虑到这一点).否则,我将重命名我的文件persistence.xml.

Also, I chose to name my file jpa.xml instead of persistence.xml; bonus points if your solution accounts for this as well. Otherwise, I'll just rename my file persistence.xml.

推荐答案

您可以在EclipseLink文档中找到答案,更具体地说,可以在

You can find your answers in the EclipseLink Documentation, more specifically in the section called Using EclipseLink JPA Extensions for Schema Generation.

您会发现这里有一个名为eclipselink.ddl-generation的属性,可能带有诸如NONE | CREATE_ONLY | DROP_AND_CREATE的值.

There you will find that there is a property called eclipselink.ddl-generation with possible values like NONE | CREATE_ONLY | DROP_AND_CREATE.

您将在此页面中找到一个名为eclipselink.ddl-generation.output-mode的附加属性.

There you will find an additional property named eclipselink.ddl-generation.output-mode, whose documentation is in this same page.

它将为您提供控制,是只生成脚本还是实际对数据库执行DDL.

It will provide you control on whether you want just to generate a script or actually execute the DDL against the database.

希望对您有帮助!

这篇关于使用EclipseLink为JPA 2.0生成DDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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