在Eclipse中使用Hibernate创建数据库的专业工作流程是什么? [英] What does a professional workflow creating a databse using Hibernate in Eclipse?

查看:136
本文介绍了在Eclipse中使用Hibernate创建数据库的专业工作流程是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道用Hibernate从头开始创建一个大型MySQL数据库的现代方式是什么。



你不会使用编写一个现代UI应用程序 - 我知道 - 所以我手写如何编写 .hbm.xml 文件为Hibernate,如果我不必?无论如何,我喜欢在使用XML之前使用Java注释(例如 @Entity @OneToMany 等)要启动的级别?



MySQL Workbench提供了一种非常简单的方法来创建MySQL方案,所以我目前所做的是在MySQL Workbench中创建我的架构并用Hibernate Tools进行反向工程。这样我创建了我的数据库我有我的注释Java文件希望正确。



但是使用MySQL Workbench感到奇怪为我创建一个数据库,我反向工程只是为了拥有我的Java文件。



所以你看到我正在寻找的是一个实用的方法来组织我的创建过程应该也可以考虑以后的迁移过程,这可能是必需的。



Hibernate的精巧工作流程是什么样的?

解决方案

没有(TM)的做法。但是从5年的hibernate经验我开始建模,然后手写DDL。我建议不要让hibernate创建你的表,因为hibernate不能创建索引和体面的约束,通常你需要一个用于测试,集成和生产环境的db init脚本。以这种方式迁移也更容易。



当表全部设置完毕后,我将让IDE由IDE生成。我总是被反向关系困惑...



开发完成后,我通常会再次分析模型以添加缺失的索引。



使用hibernate,您无法定义主键,如 GENERATE ALWAYS ,约束如 id> 0 。 Hibernate还将使用默认值序列 ant不会为每个表添加序列。不支持较新的oracle和SQL Server功能。



我读了一次,在模型实现后应该使用hibernate,但它必须是3.x,我猜Hibernate 4.x学习了一些新的技巧。 p>

I am not sure what's the "modern" way of creating a large MySQL database from scratch with Hibernate.

You would not use assembly to write a modern UI Application - that I know - so do I write .hbm.xml files for Hibernate by hand if I don't have to? Anyway I would prefer to use Java Annotations (e.g. @Entity, @OneToMany, etc.) before using XML but is that the level to start?

MySQL Workbench offers a quite straight forward way to create MySQL schemes, so what I do at the moment is that I create my schema in MySQL Workbench and reverse engineer it with Hibernate Tools. That way I have created my database and I have my annotated Java files which are hopefully correct.

But it feels strange to use MySQL Workbench to create a database for me that I reverse engineer just to have my Java files.

So you see what I am looking for is a practical way to organize my creation process that should also consider later migration processes that might be necessary.

What does an elaborate workflow for Hibernate look like?

解决方案

There is not the way (TM) to do it. But from 5 years of hibernate experience I start with modeling, then hand writing the DDL. I recommend against letting hibernate create your tables because hibernate cannot create indexes and decent constraints and normally you need a db init script for test, integration and production environment. Migrating this way is also easier.

When the tables are all set up I let the entities be generated by the IDE. I always get confused by the inverse relationships...

After the development is done I normally analyze the model again to add missing indices.

With hibernate you cannot define primary keys like GENERATE ALWAYS, constrains like id > 0. Hibernate will also use as default one sequence ant will not add sequences per table. The newer oracle and SQL server features are not supported.

I read once that hibernate should be used after the model is implemented but it must have been 3.x and I guess hibernate 4.x learned some new tricks.

这篇关于在Eclipse中使用Hibernate创建数据库的专业工作流程是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆