如何使用Hibernate创建数据库Schema [英] How to creata database Schema using Hibernate

查看:447
本文介绍了如何使用Hibernate创建数据库Schema的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读 Hibernate:hbm2ddl.auto =在生产中更新?后,出现了一些问题。
首先,我使用Hibernate的原因是数据库供应商无关(不需要写10个版本的相同sql查询,例如tsql vs. sql)。

After reading Hibernate: hbm2ddl.auto=update in production? some questions arose. First of all, the reason for I'm using Hibernate is to be database vendor independent (no need to write 10 versions of the "same" sql query, eg. tsql vs. sql).

当我们创建数据库模式(生产环境)时出现我的问题。

My problem appears when it's time to create the database schemas (production environment). As far as I can see I have two alternatives.


  1. hbm2dll = update

  2. pure sql ddl)。

第一种方法在上面的线程中广泛讨论。
第二个选择是坏的,因为这意味着我回到我的第一个问题:不想创建依赖于数据库供应商的sql语句。 (如果all(Hibernate支持的数据库的最后)正在实施 DDL (用于定义和检查数据库结构的SQL子集)等于)。

The first alternative is widely discussed in the thread above. The second alternative is bad because that means I'm back to my first problem: "Don't want to create sql statements that are database vendor dependent". (This statement could be false if "all" (atlast the databases Hibernate support) are implementing the DDL (The subset of SQL used for defining and examining the structure of a database.) equal).

推荐答案

在开发/暂存模式中执行所有更改,并手动传输和执行生产脚本hibernate运行它们)。脚本可能需要一些调整,因为hbm2ddl更新不能覆盖所有情况。

Do all changes in development/staging mode and transfer and execute scripts in production manually (or automatically, but don't let hibernate run them). The scripts may need some tunning since hbm2ddl update does not cover all cases.

事实上,我从来没有让hibernate对任何数据库运行ddl。我使用hbm2ddl生成文本:

In fact I never let hibernate run ddl against any database. I use hbm2ddl to generate text:

org.hibernate.tool.hbm2ddl.SchemaExport --config=hibernate.cfg.xml --text --format --delimiter=;

org.hibernate.tool.hbm2ddl.SchemaUpdate --config=hibernate.cfg.xml --text --format --delimiter=;

这篇关于如何使用Hibernate创建数据库Schema的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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