Java 如何关闭 hbm2ddl?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3179765/
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
How to turn off hbm2ddl?
提问by Alex
I couldn't find a reference on how to switch hbm2ddl off.
我找不到有关如何关闭 hbm2ddl 的参考。
采纳答案by Pascal Thivent
Just omitting hibernate.hbm2ddl.auto
defaults to Hibernate not doing anything. From the reference documentation:
只是省略hibernate.hbm2ddl.auto
默认 Hibernate 不做任何事情。从参考文档:
1.1.4. Hibernate configuration
The
hbm2ddl.auto
option turns on automatic generation of database schemas directly into the database. This can also be turned off by removing the configuration option, or redirected to a file with the help of the SchemaExport Ant task.
1.1.4. 休眠配置
该
hbm2ddl.auto
选项会直接将数据库模式自动生成到数据库中。 这也可以通过删除配置选项来关闭,或者在 SchemaExport Ant 任务的帮助下重定向到一个文件。
Setting hbm2ddl.auto
to none
(undocumented) might generate a warning, such as: org.hibernate.cfg.SettingsFactory - Unrecognized value for "hibernate.hbm2ddl.auto": none
设置hbm2ddl.auto
为none
(未记录)可能会产生警告,例如:org.hibernate.cfg.SettingsFactory - Unrecognized value for "hibernate.hbm2ddl.auto": none
回答by Bozho
in hibernate.properties
在 hibernate.properties 中
hibernate.hbm2ddl.auto=validate
Of course, the place to configure it depends on the way you configure your hibernate - if it is programatically, set the property there. If it is from hibernate.cfg.xml:
当然,配置它的位置取决于您配置休眠的方式 - 如果以编程方式,请在那里设置属性。如果它来自 hibernate.cfg.xml:
<property name="hibernate.hbm2ddl.auto">validate</property>
回答by Julien BRENELIERE
You can switch it off by :
您可以通过以下方式关闭它:
hibernate.hbm2ddl.auto=none
It's undocumented but priceless !
这是无证但无价的!
回答by Andres Saarem?ts
To get this one clear, one should look into the source of org.hibernate.cfg.SettingsFactory
(you might see something else depending on the version used):
为了弄清楚这一点,应该查看以下来源org.hibernate.cfg.SettingsFactory
(根据所使用的版本,您可能会看到其他内容):
String autoSchemaExport = properties.getProperty( AvailableSettings.HBM2DDL_AUTO );
if ( "validate".equals(autoSchemaExport) ) {
settings.setAutoValidateSchema( true );
}
else if ( "update".equals(autoSchemaExport) ) {
settings.setAutoUpdateSchema( true );
}
else if ( "create".equals(autoSchemaExport) ) {
settings.setAutoCreateSchema( true );
}
else if ( "create-drop".equals( autoSchemaExport ) ) {
settings.setAutoCreateSchema( true );
settings.setAutoDropSchema( true );
}
else if ( !StringHelper.isEmpty( autoSchemaExport ) ) {
LOG.warn( "Unrecognized value for \"hibernate.hbm2ddl.auto\": " + autoSchemaExport );
}
In the org.hibernate.cfg.Settings
class those variables are initialized as:
在org.hibernate.cfg.Settings
类中,这些变量被初始化为:
private boolean autoCreateSchema;
private boolean autoDropSchema;
private boolean autoUpdateSchema;
private boolean autoValidateSchema;
so these default to false.
所以这些默认为false。
Omitting the hibernate.hbm2ddl.auto
setting should switch off the HBM2DDL_AUTO
functionality as would suggested hibernate.hbm2ddl.auto = none
, but on the latter case you get a warning in the log.
省略hibernate.hbm2ddl.auto
设置应该HBM2DDL_AUTO
按照建议关闭功能hibernate.hbm2ddl.auto = none
,但在后一种情况下,您会在日志中收到警告。
回答by gdrt
This property is not required. Just delete the hibernate.hbm2ddl.auto
entry completely from the xml file.
此属性不是必需的。只需hibernate.hbm2ddl.auto
从 xml 文件中完全删除条目。
回答by jstadler
If you enter an unsupported value it will tell you which ones are supported:
o.h.b.i.SessionFactoryBuilderImpl : Unrecognized hbm2ddl_auto value : bla. Supported values include 'create', 'create-drop', 'update', 'none' and 'validate'. Ignoring
如果您输入不支持的值,它会告诉您支持哪些值:
o.h.b.i.SessionFactoryBuilderImpl : Unrecognized hbm2ddl_auto value : bla. Supported values include 'create', 'create-drop', 'update', 'none' and 'validate'. Ignoring
And the value none
is the default, is officially supported and documented:
https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl
该值none
是默认值,官方支持和记录:https:
//docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl