从JPA实体反向设计DDL [英] Reverse engineer DDL from JPA entities

查看:123
本文介绍了从JPA实体反向设计DDL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩一些JPA的东西,改变映射来看看它们应该如何等等。这是基本的实验。然而,我找不到一个只读取我的实体并为我生成表格模式的工具。我试图在JBoss工具中找到类似这样的东西,但是nada。 Eclipse集成将是一个巨大的优势,但我会采取一个命令行工具或一个蚂蚁的任务。



任何想法?

解决方案

我不认为JPA有这样做的通用方法,您必须直接使用底层JPA实现来实现此目的。



对于 Hibernate ,有以下几种可能性:


  • 使用方法 duffymo ,这让Hibernate自动更新数据库模式。

  • 如果您不希望这样,您可以使用 hbm2ddl 工具。 nofollow noreferrer> Hibernate Tools (注意:链接太烂了,但显然他们的主页现在有点坏了)。您可以使用它从JPA实体自动生成数据库创建脚本;还有Maven和Ant的插件会自动调用 hbm2ddl



EclipseLink (以前称为Oracle TopLink,JPA 2.0 RI)请参阅使用EclipseLink JPA扩展模式生成。原则上它与Hibernate非常相似,但乍看之下,我没有看到任何可用作创建数据库脚本的独立实用程序。



其他JPA实现(BEA / Oracle Kodo,Apache OpenJPA)可能有自己的具体实现方法。


I'm playing around with some JPA stuff, changing the mappings to see how they're supposed to be etc. It's basic experimentation. However I can't find a tool that will simply read my entities and then generate the table schema for me. I tried to find something like this in JBoss tools but nada. Eclipse integration will be a huge plus but i'll take a command line tool or an ant task.

Any ideas?

解决方案

I don't think there is an universal way of doing this with JPA, you have to directly use the underlying JPA implementation to achieve this.

For Hibernate, there are several possibilities:

  • Use the method duffymo posted earlier, that makes Hibernate update the database schema automatically.
  • If you do not want that, you can use the hbm2ddl tool from Hibernate Tools (note: link sucks, but apparently their home page is a bit broken right now). You can use that to automatically generate database creation scripts from your JPA entities; there are also plugins for Maven and Ant that invoke hbm2ddl automatically.

For EclipseLink (formerly Oracle TopLink, the JPA 2.0 RI) see Using EclipseLink JPA Extensions for Schema Generation. In principle it is very similar to Hibernate, although at first glance I don't see anything that could be used as a stand-alone utility for creating a DB script.

Other JPA implementations (BEA/Oracle Kodo, Apache OpenJPA) probably have their own specific methods of achieving this.

这篇关于从JPA实体反向设计DDL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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