java 弹簧靴。从 MySql 模式自动创建实体类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33620251/
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
Spring boot. Automatically create Entity classes from MySql schema
提问by SeaBiscuit
I have been working on EER diagram model for my Mysql base for the last 7 days. It is a rather complicated model with lots of connections and attributes. Now i know spring boot automatically creates tables based on your entity classes(including foreign keys and other settings) if you use spring.jpa.hibernate.ddl-auto = update in your application.properties, but is it possible to create entity classes after providing good credentials to DataSource object based on tables withing schema?
在过去的 7 天里,我一直在为我的 Mysql 基础研究 EER 图模型。这是一个相当复杂的模型,有很多连接和属性。现在我知道如果您在 application.properties 中使用 spring.jpa.hibernate.ddl-auto = update,spring boot 会根据您的实体类(包括外键和其他设置)自动创建表,但是是否可以在之后创建实体类根据具有模式的表为 DataSource 对象提供良好的凭据?
Point is i would probably need another 3-4 days of back-end coding to create all the classes with all the attribute, relationships etc.
重点是我可能需要另外 3-4 天的后端编码来创建具有所有属性、关系等的所有类。
Given the fact it can only be done in one correct way, based on schema tables and it is not really rocket science. Why not do the thing just once?
鉴于它只能以一种正确的方式完成,基于模式表,这并不是真正的火箭科学。为什么不只做一次呢?
There is this question Automatically create Entities from databasebut 1. i am using spring boot not JPA project and second blog is no longer active.
有这个问题Automatically create Entities from databasebut 1. 我使用的是 spring boot 而不是 JPA 项目,第二篇博客不再活跃。
Any hints?
任何提示?
回答by Pavan
Just figured it out. I used the hibernate perspective in eclipse to connect to a database, create a cfg.xml and run the project as hibernate configurations, create a new reveng.xml config and that will work. More detailed answer can be found in the article below.
刚刚想通了。我使用 eclipse 中的 hibernate 透视图连接到数据库,创建一个 cfg.xml 并将项目作为 hibernate 配置运行,创建一个新的 reveng.xml 配置,这将起作用。更详细的答案可以在下面的文章中找到。
http://o7planning.org/en/10125/using-hibernate-tools-generate-entity-classes-from-tables
http://o7planning.org/en/10125/using-hibernate-tools-generate-entity-classes-from-tables
Hope it will help someone!!
希望它会帮助某人!!
回答by davidxxx
There is this question Automatically create Entities from database but 1. i am using spring boot not JPA project and second blog is no longer active.
有这个问题 Automatically create Entities from database but 1. 我使用的是 spring boot 而不是 JPA 项目,第二篇博客不再活跃。
Under the woods, Spring boot uses JPA and more specifically Hibernate since it has bad compatibility with other JPA implmentations such as EclipseLink.
实际上,Spring Boot 使用 JPA,更具体地说是 Hibernate,因为它与其他 JPA 实现(例如 EclipseLink)的兼容性很差。
Why don't you use Dali Eclipse plugin ? https://www.eclipse.org/webtools/dali/docs/3.2/user_guide/tasks006.htm
你为什么不使用 Dali Eclipse 插件? https://www.eclipse.org/webtools/dali/docs/3.2/user_guide/tasks006.htm
It has a wizard with many options and it addresses well this kind of need. The real drawback when I use it and we cannot store our orm configuration. So, since you have many tables, I advise you to generate it in an incremental way your entities.
它有一个有很多选项的向导,它很好地满足了这种需求。我使用它时的真正缺点是我们无法存储我们的 orm 配置。因此,由于您有很多表,我建议您以增量方式生成您的实体。