简体   繁体   English

哪个是最好的工具从 MySQL DB 生成 Hibernate map

[英]Which is the best tool Generate Hibernate map from MySQL DB

I am using hibernate in my servlet to access the database.DB contains lot of foreign keys, composite keys and backward references..我在我的 servlet 中使用 hibernate 来访问数据库。DB 包含很多外键、复合键和向后引用。

Can you suggest me some tools to do reverse engineer the MySQL DB to Object oriented file in java so that I can use it with hibernate. Can you suggest me some tools to do reverse engineer the MySQL DB to Object oriented file in java so that I can use it with hibernate.

IDEs usually provide such generating of entities. IDE 通常提供这样的实体生成。 For example, if you use Netbeans, just go File/New/Persistence/Entity Classes from Database within a Java SE/Java EE-Project to generate JPA entities. For example, if you use Netbeans, just go File/New/Persistence/Entity Classes from Database within a Java SE/Java EE-Project to generate JPA entities. By the way, it's a good idea to use standard JPA(2) mechanisms where possible, in order to not being dependant on a specific O/R-Mapper (such as Hibernate) or database.顺便说一句,最好尽可能使用标准 JPA(2) 机制,以便不依赖于特定的 O/R-Mapper(例如 Hibernate)或数据库。

I agree with Cris,我同意克里斯,

The version 0.5.5 of Minuteproject 4 JPA2 generates also for composite key a class annotated with @Embeddable. Minuteproject 4 JPA2的 0.5.5 版本还为复合键生成了一个 class 用 @Embeddable 注释。 The entity class has the @EmbeddedId as entity with the reference to the Embeddable class.实体 class 具有 @EmbeddedId 作为实体,并引用可嵌入的 class。 For the foreign keys part of the composite key, it generates the associated @MapsId.对于复合键的外键部分,它会生成关联的@MapsId。

Meanwhile the JPA2 templates do not cover yet the composite foreign key pattern.同时,JPA2 模板还没有涵盖复合外键模式。

Hope it helped.希望它有所帮助。

Have a look at JBoss Hibernate Tools which allows you to reverse engineer existing databases.查看JBoss Hibernate 工具,它允许您对现有数据库进行逆向工程。

The best one is MinuteProject in my opinion !我认为最好的是 MinuteProject !

Check it on:检查它:

http://javacodesamples.wordpress.com/2011/02/04/jpa2-reverse-engineering-tool/ http://javacodesamples.wordpress.com/2011/02/04/jpa2-reverse-engineering-tool/

http://www.dzone.com/links/jpa2_reverseengineering_with_minuteproject_pragma.html http://www.dzone.com/links/jpa2_reverseengineering_with_minuteproject_pragma.html

http://javacodesamples.wordpress.com/2010/09/04/minute-project-episode-1-the-productivity-provider/ http://javacodesamples.wordpress.com/2010/09/04/minute-project-episode-1-the-productivity-provider/

It has also a Spring + Hibernate track beside the JPA so you can used that for you hibernate needs.它在 JPA 旁边还有一个 Spring + Hibernate 轨道,因此您可以使用它来满足您的 ZCB1F008EEBF5012C4EF477 需求。

We use Hibernate Tools to generate *.hbm.xml files with the help of a hibernate.reveng.xml file. We use Hibernate Tools to generate *.hbm.xml files with the help of a hibernate.reveng.xml file. And then, we apply Hibernate Synchronizer plugin of Eclipse to generate Entities and DAOs using *.hbm.xml files.然后,我们应用Eclipse 的 Hibernate 同步器插件使用*.hbm.xml文件生成实体和 DAO。

hibernate.reveng.xml fill the parts where auto generation cannot guess what you have in your mind. hibernate.reveng.xml填补了自动生成无法猜测您的想法的部分。

Hibernate Synchronizer has the main advantage of creating base classes for your generated entities/daos. Hibernate 同步器的主要优点是为生成的实体/daos 创建基类 You add your custom properties/methods to subclasses (again automatically generated) of the base classes.您将自定义属性/方法添加到基类的子类(再次自动生成)。 The advantage here, is if you make changes to your database and regenerate, the changes you make (to subclasses) rest untouched.这里的优势是,如果您对数据库进行更改并重新生成,那么您对(对子类)所做的更改 rest 不会受到影响。

Whatever tool you choose pay attention to build a system where code generation is easy and painless, not only for the first time but also during advanced phases of the project.无论您选择什么工具,都要注意构建一个代码生成轻松无痛的系统,不仅是第一次,而且在项目的高级阶段也是如此。 If not you'll lose all the advantages.否则,您将失去所有优势。

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

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