java 基于 mysql db 创建基本映射的 Hibernate 工具

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2384433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:54:16  来源:igfitidea点击:

Hibernate tool to create basic mappings based on a mysql db

javahibernateormreverse-engineering

提问by Blankman

Are there any tools that can look at a database, and generate the basic mapping files?

有没有可以查看数据库并生成基本映射文件的工具?

It would be great if it could take a database, and create the actual model (java classes) with annotations, but not sure if that exists?

如果它可以采用数据库并创建带有注释的实际模型(java 类),那将会很棒,但不确定是否存在?

回答by Pascal Thivent

Hibernate 3 has a toolset called Hibernate Toolsthat provides an Eclipse plugin and an Ant task that both support Reverse Engineering:

Hibernate 3 有一个名为Hibernate Tools的工具集,它提供了一个 Eclipse 插件和一个 Ant 任务,它们都支持逆向工程

Reverse Engineering:The most powerful feature of Hibernate Tools is a database reverse engineering tool that can generate domain model classes and Hibernate mapping files, annotated EJB3 entity beans, HTML documentation or even an entire JBoss Seam application in seconds!

...

Ant task:The Hibernate3 tools include a unified Ant task that allows you to run schema generation, mapping generation, or Java code generation as part of your build.

逆向工程:Hibernate Tools 最强大的功能是数据库逆向工程工具,它可以在几秒钟内生成域模型类和 Hibernate 映射文件、带注释的 EJB3 实体 bean、HTML 文档甚至整个 JBoss Seam 应用程序!

...

Ant 任务:Hibernate3 工具包括一个统一的 Ant 任务,它允许您在构建过程中运行模式生成、映射生成或 Java 代码生成。

For the Eclipse plugin, have a look at this sectionof the documentation. For the Ant task, have a look at the section about reverse engineeringand optionally how to control it.

对于 Eclipse 插件,请查看文档的这一部分。对于 Ant 任务,请查看有关逆向工程和可选的如何控制它的部分

Note that other IDEs also provide support for reverse engineering (see Hibernate Reverse Engineering for Netbeans 6.5and Generating Persistence Mappings from Database Schemafor IntelliJ).

请注意,其他 IDE 也提供对逆向工程的支持(请参阅Netbeans 6.5 的 Hibernate 逆向工程IntelliJ 的数据库架构生成持久性映射)。

回答by shyam

I just happened to stumble across this problem and I think I have found a perfect tool for the job.

我碰巧遇到了这个问题,我想我已经找到了一个完美的工具。

http://hibernatepojoge.sourceforge.net/

http://hibernatepojoge.sourceforge.net/



Features :(in case you are lazy to go through the provided link)

特点:(以防你懒得浏览提供的链接)

  • Java objects representing each table using annotations for use with Hibernate.
  • A JUnit test case per table that uses the objects generated to create, populate, save, retrieve and compare results
  • DAO per class
  • The appropriate enumeration files
  • Spring and hibernate configuration
  • DAO layers
  • A data factory class per schema to return a pre-populated object with random data (for boundary checking, database population, etc)
  • 使用注释来表示每个表的 Java 对象,以便与 Hibernate 一起使用。
  • 每个表的 JUnit 测试用例,使用生成的对象来创建、填充、保存、检索和比较结果
  • 每个类的 DAO
  • 适当的枚举文件
  • Spring和hibernate配置
  • DAO 层
  • 每个模式的数据工厂类返回带有随机数据的预填充对象(用于边界检查、数据库填充等)

Also supports:

还支持:

  • Join tables including those with additional fields in link tables
  • Polymorphism/inheritance support
  • Composite Keys
  • One-To-One, many-to-one, many-to-many, etc
  • Multiple schema support (4 modes)
  • Natural Keys
  • Enumerations (including those entries which cannot be mapped cleanly onto the java world)
  • A whole bunch of more stuff (see sample.xml)
  • 联接表,包括那些在链接表中具有附加字段的表
  • 多态/继承支持
  • 复合键
  • 一对一、多对一、多对多等
  • 多模式支持(4 种模式)
  • 自然键
  • 枚举(包括那些不能完全映射到 Java 世界的条目)
  • 一大堆更多的东西(见sample.xml)


I would also like to say that setting this up is quite straight forward; You just have to have a hibernate configuration file and the jar file downloaded from the site. Then it's just a matter executing a jar file, passing the config.xmlas a parameter!

我还想说,设置它非常简单;您只需要一个休眠配置文件和从站点下载的 jar 文件。那么它只是执行一个 jar 文件,config.xml作为参数传递的问题!

回答by PaulP1975

If you are using eclipse or ant...

如果您使用的是 eclipse 或 ant ...

Jboss tools

Jboss 工具

回答by Will Marcouiller

You might find what you need here, I found it on the fly: MyGeneration.

你可能会在这里找到你需要的东西,我很快就找到了:MyGeneration

I know there are others that exist, but I don'T remember by heart. Hope this helps!

我知道还有其他人存在,但我不记得了。希望这可以帮助!