hibernate mysql schema指什么意思,如何使用Hibernate创建数据库Schema

文章探讨了在生产环境中使用Hibernate时,如何处理数据库模式更新的问题。作者希望保持数据库供应商的独立性,避免编写特定于数据库的SQL。面临的选择是使用'hbm2ddl.auto=update'或手动编写DDL脚本。由于'hbm2ddl.auto=update'可能不覆盖所有情况且可能产生数据库供应商依赖,作者倾向于在开发阶段进行更改,然后手动或自动在生产环境中执行调整过的DDL脚本。
摘要由CSDN通过智能技术生成

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.

hbm2dll = update

pure sql (ddl) scripts.

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).

解决方案

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.

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=;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值