简体   繁体   English

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

[英]Hibernate tool to create basic mappings based on a mysql db

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类),但不确定是否存在,那将会很棒?

Hibernate 3 has a toolset called Hibernate Tools that 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! 逆向工程: Hibernate Tools最强大的功能是数据库逆向工程工具,可以在几秒钟内生成域模型类和Hibernate映射文件,带注释的EJB3实体bean,HTML文档甚至整个JBoss Seam应用程序!

... ...

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. Ant任务: Hibernate3工具包含一个统一的Ant任务,允许您在构建过程中运行模式生成,映射生成或Java代码生成。

For the Eclipse plugin, have a look at this section of the documentation. 对于Eclipse插件,请查看文档的这一部分 For the Ant task, have a look at the section about reverse engineering and optionally how to control it . 对于Ant任务,请查看有关逆向工程的部分以及可选的控制方法

Note that other IDEs also provide support for reverse engineering (see Hibernate Reverse Engineering for Netbeans 6.5 and Generating Persistence Mappings from Database Schema for IntelliJ). 请注意,其他IDE也提供对逆向工程的支持(请参阅针对Netbeans 6.5的Hibernate逆向工程 IntelliJ的数据库架构生成持久性映射 )。

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

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) 多架构支持(4种模式)
  • Natural Keys 自然键
  • Enumerations (including those entries which cannot be mapped cleanly onto the java world) 枚举(包括那些无法完全映射到java世界的条目)
  • A whole bunch of more stuff (see sample.xml) 一堆更多的东西(参见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. 您只需拥有一个hibernate配置文件和从该站点下载的jar文件。 Then it's just a matter executing a jar file, passing the config.xml as a parameter! 然后,只需执行一个jar文件,将config.xml作为参数传递!

If you are using eclipse or ant... 如果你正在使用eclipse或ant ...

Jboss tools Jboss工具

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! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM