hibernate.hbm2ddl.auto update不能创建表

还没有开通你的开心账户?使用其他账号登录:
[转载]hibernate.hbm2ddl.auto—Hibernate自动建表的配置_ETHAN_新浪博客
[转载]hibernate.hbm2ddl.auto—Hibernate自动建表的配置_ETHAN_新浪博客
本转帖分类:&&
&&上一帖:
下一帖:&&
(%)点击发表你的观点
05-21 18:0005-21 18:0105-21 18:0505-21 18:0605-21 18:0705-21 18:1005-21 18:1105-21 18:1205-21 18:1205-21 18:20
热门转帖:
最新专题:
&2016 开心网java - Hibernate hbm2ddl.auto possible values and what they do? - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
I really want to know more about the update, export and the values that could be given to hibernate.hbm2ddl.auto
I need to know when to use the update and when not? And what is the alternative?
These are changes that could happen over DB:
New tables
new columns in old tables
columns deleted
data type of a column changed
a type of a column changed it attributes
tables have been dropped
values of a column has changed
In each case what is the best solution?
From the :
hibernate.hbm2ddl.auto
Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.
e.g. validate | update | create | create-drop
So the list of possible options are,
validate: validate the schema, makes no changes to the database.
update: update the schema.
create: creates the schema, destroying previous data.
create-drop: drop the schema at the end of the session.
These options seem intended to be developers tools and not to facilitate any production level databases, you may want to have a look at th
20.8k49142214
The configuration property is called hibernate.hbm2ddl.auto
In our development environment we set hibernate.hbm2ddl.auto=create-drop to drop and create a clean database each time we deploy, so that our database is in a known state.
In theory, you can set hibernate.hbm2ddl.auto=update to update your database with changes to your model, but I would not trust that on a production database. An earlier version of the documentation said that this was experimental, I do not know the current status.
Therefore, for our production database, do not set hibernate.hbm2ddl.auto - the default is to make no database changes. Instead, we manually create an SQL DDL update script that applies changes from one version to the next.
12.6k43671
There's also the undocumented value of "none" to disable it entirely.
I would use
for updating your db. hibernate's schema update feature is really only o.k. for a developer while they are developing new features. In a production situation, the db upgrade needs to be handled more carefully.
3,19442136
If you don't want to use Strings in your app and are looking for predefined constants have a look at org.hibernate.cfg.AvailableSettings class included in the Hibernate JAR, where you'll find a constant for all possible settings. In your case for example:
* Auto export/update schema using hbm2ddl tool. Valid values are &tt&update&/tt&,
* &tt&create&/tt&, &tt&create-drop&/tt& and &tt&validate&/tt&.
String HBM2DDL_AUTO = "hibernate.hbm2ddl.auto";
1,82012330
I dedicated a
for the most common Hibernate DDL generation strategies:
The hibernate.hbm2ddl.auto="update" is convenient but less flexible if you plan on adding functions or executing some custom scripts.
The most flexible approach is to generate the DDL scripts with org.hibernate.tool.ant.HibernateToolTask and then use a component to execute the scripts on context startup. The destroy scripts are called when the Spring context is closed.
The second approach is much more flexible, especially if you want to mix .
Needless to say that this is only an Integration testing concern, since for production environment we use .
25.4k52556
I Think you should have to concentrate on the
SchemaExport Class
this Class Makes Your Configuration Dynamic
So it allows you to choose whatever suites you best...
1,36611120
if you want to use hibernate.hbm2ddl.auto it's good if you remove this attribute. In large System, developer always prefer not to use that is
"don't use hibernate.hbm2ddl.auto in you application. just remove this from xml"
it will use default hbm2ddl
protected by ♦
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10
on this site.
Would you like to answer one of these
Stack Overflow works best with JavaScript enabled下次自动登录
现在的位置:
& 综合 & 正文
hibernate.hbm2ddl.auto 的设置
&?xml version='1.0' encoding='UTF-8'?&
&!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&
&!-- Generated by MyEclipse Hibernate Tools.
&hibernate-configuration&
&session-factory&
&property name="connection.username"&root&/property&
&property name="connection.url"&
jdbc:mysql://localhost:3306/myhibernate
&/property&
&property name="dialect"&
org.hibernate.dialect.MySQLDialect
&/property&
&property name="connection.driver_class"&
com.mysql.jdbc.Driver
&/property&
&property name="hbm2ddl.auto"&create&/property&
&property name="c3p0.min_size"&5&/property&
&property name="c3p0.max_size"&20&/property&
&property name="c3p0.timeout"&300&/property&
&property name="c3p0.max_statements"&50&/property&
&property name="c3p0.idle_test_period"&3000&/property&
&property name="show_sql"&true&/property&
&property name="format_sql"&true&/property&
&property name="myeclipse.connection.profile"&mysql&/property&
&property name="connection.password"&&/property&
&mapping resource="hello/Message.hbm.xml" /&
&/session-factory&
&/hibernate-configuration&
加载hibernate时,验证创建数据库表结构create
每次加载hibernate,重新创建数据库表结构,这就是导致数据库表数据丢失的原因。create-drop
加载hibernate时创建,退出是删除表结构update
加载hibernate自动更新数据库结构在本机开发调试初始化数据的时候可以选择create、update等。但是网站发布正式版本的时候,对数据库现有的数据或表结构进行自动的更新是很危险的。此时此刻应该由DBA同志通过手工的方式进行后台的数据库操作。hibernate.hbm2ddl.auto的值建议是“none”或“validate”。“validate”应该是最好的选择:这样 spring在加载之初,如果model层和数据库表结构不同,就会报错,这样有助于技术运维预先发现问题。
&&&&推荐文章:
【上篇】【下篇】<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&}

我要回帖

更多关于 hbm2ddl.auto默认值 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信