eclipse 从数据库表生成java域对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/880785/
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-09-19 13:43:16  来源:igfitidea点击:

generate java domain objects from database table

javaeclipsespringspring-mvcdomain-driven-design

提问by cometta

may i know in eclipse, is there any feature that will auto generate domain objects with all table relationship properly mapped in class?

我可以知道在 Eclipse 中,是否有任何功能可以自动生成所有表关系正确映射到类中的域对象?

can provide me with some reference articles on this?

可以给我提供一些这方面的参考文章吗?

采纳答案by Vinko Vrsalovic

You can use something like Hibernateto accomplish this

你可以使用像Hibernate这样的东西来完成这个

This plugin set for Eclipsecalled Hibernate Tools for Eclipse and ANT will do most of the work for you.

这个Eclipse 插件集称为 Hibernate Tools for Eclipse and ANT 将为您完成大部分工作。

In particular it will do 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 应用程序!

回答by rlopez

Telosys code generatordoes this kind of job. It's an Eclipse plugin, it uses the database schema to create a light model that is used to generate the Java code.

Telosys 代码生成器可以完成这种工作。它是一个Eclipse 插件,它使用数据库模式创建用于生成 Java 代码的轻型模型。

There are some predefined templates available on GitHub (for JPA, POJO, Documentation, Spring MVC, etc )

GitHub 上有一些预定义的模板(用于 JPA、POJO、文档、Spring MVC 等)

See http://www.telosys.org

http://www.telosys.org

and http://marketplace.eclipse.org/content/telosys-tools

http://marketplace.eclipse.org/content/telosys-tools

Templates : https://github.com/telosys-templates-v3

模板:https: //github.com/telosys-templates-v3

Articles about code generation with Telosys :

关于使用 Telosys 生成代码的文章:

回答by elvisanandkumar

I have a solution for you i.e to create auto generate domain objects with all table relationship properly mapped in class ...Try Dal4jyes you can find it in sourceforge.net/p/dal4j/wiki/DAL4j is a Command Line and Framework tool that can be used to reverse engineer a MySQL or SQLServer database schema into a set of JPA Entity Beans.

我有一个解决方案,即创建自动生成域对象,其中所有表关系都正确映射到类中...试试Dal4j是的,你可以在sourceforge.net/p/dal4j/wiki/ 中找到它DAL4j 是一个命令行和框架工具可用于将 MySQL 或 SQLServer 数据库模式反向工程为一组 JPA 实体 Bean。

DAL4j can be useful for scenarios where there is an existing database schema but a technology other that JPA is used by applications to interact with the database. DAL4j can provide an easy way to migrate your code base from other technologies such as JDBC or Hibernate to JPA.

DAL4j 可用于存在现有数据库架构但应用程序使用 JPA 以外的技术与数据库交互的场景。DAL4j 可以提供一种简单的方法将您的代码库从其他技术(例如 JDBC 或 Hibernate)迁移到 JPA。

The beans generated can be 1 or two types: Simple or Framework. Simple beans are standard pojo classes managed by your application using JPA semantics. Framework generated pojos use the DAL4j framework DAO generic to simplify CRUD operations.

生成的 bean 可以是一种或两种类型:Simple 或 Framework。简单 bean 是由您的应用程序使用 JPA 语义管理的标准 pojo 类。框架生成的 pojo 使用 DAL4j 框架 DAO 泛型来简化 CRUD 操作。

DAL4j provides optional hooks to allow you integrate encryption/decryption of data fields that must be encrypted in the database.

DAL4j 提供了可选的钩子,允许您集成必须在数据库中加密的数据字段的加密/解密。

Last, DAL4j provides a set of Generic classes that can be used to simplify creation of Session Beans which perform CRUD operations using generated Entities.

最后,DAL4j 提供了一组通用类,可用于简化会话 Bean 的创建,会话 Bean 使用生成的实体执行 CRUD 操作。

I think you will find this article feasible....

我想你会发现这篇文章是可行的......

回答by Aries McRae

You can use Hibernate Tools 3.0.0.GA either via Eclipse or ANT to auto-generate your hibernate domain entities directly from your database tables.

您可以通过 Eclipse 或 ANT 使用 Hibernate Tools 3.0.0.GA 直接从您的数据库表自动生成您的休眠域实体。

See tutorial here : http://docs.jboss.org/tools/3.0.0.GA/en/hibernatetools/html_single/index.html

请参阅此处的教程: http://docs.jboss.org/tools/3.0.0.GA/en/hibernatetools/html_single/index.html

回答by gis_wild

if you use grails, you can generate domain objects with GRAG http://sourceforge.net/projects/grag

如果您使用 grails,则可以使用 GRAG http://sourceforge.net/projects/grag生成域对象

回答by Jherico

You want an object relational mappingof which Hibernate is the most popular for Java. The hibernate tools are typically better for taking annotated classes and using them to generate a schema, as opposed to vice versa, which is what you sound like you're doing. I suspect you'll be doing a lot of hand-annotating if you're working with a legacy DB schema.

您需要一个 对象关系映射,其中 Hibernate 是 Java 中最受欢迎的。休眠工具通常更适合采用带注释的类并使用它们来生成模式,反之亦然,这听起来像是在做。我怀疑如果您使用的是遗留数据库模式,您将需要进行大量手工注释。

回答by Lyju I Edwinson

I use eclipse for java development, but when it comes to generating domain entities I use Net beans.

我使用 eclipse 进行 java 开发,但是在生成域实体时我使用 Net bean。

Create an EJB module, and then right click and generate entities. You need to set up the database also you can select the tables you want visually.

创建一个 EJB 模块,然后右键单击并生成实体。您需要设置数据库,也可以直观地选择所需的表。

Regards Lyju

问候 Lyju

回答by Michael Shang

It feels like another rather common question that people always run into.

感觉就像人们总是遇到的另一个相当普遍的问题。

The link below links to a blog detailed enough for me to learn how to generate entities from database schema the first time. http://shengwangi.blogspot.com/2014/12/how-to-create-java-classes-from-tables.html

下面的链接链接到一个足够详细的博客,让我第一次学习如何从数据库模式生成实体。 http://shengwangi.blogspot.com/2014/12/how-to-create-java-classes-from-tables.html

Just in case, the following link refers to eclipse help page. This link should never expire: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jpt.doc.user%2Ftasks021.htm

以防万一,以下链接指的是 eclipse 帮助页面。此链接永不过期:http: //help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jpt.doc.user%2Ftasks021.htm

I downloaded JBoss and failed to understand how it works. I think the plugin that I used is Hibernate Tools but I am not sure as I did not install any new plugin for this purpose. I am using Eclipse Luna for EE.

我下载了 JBoss,但无法理解它是如何工作的。我认为我使用的插件是 Hibernate Tools,但我不确定,因为我没有为此安装任何新插件。我正在将 Eclipse Luna 用于 EE。

Hope this helps.

希望这可以帮助。