我找不到关于如何关闭hbm2ddl的参考资料。
答案 0 :(得分:75)
只是忽略hibernate.hbm2ddl.auto
默认为Hibernate没有做任何事情。从参考文档:
1.1.4. Hibernate configuration
hbm2ddl.auto
选项开启 自动生成数据库 模式直接进入数据库。 也可以通过删除配置选项关闭此功能, 或者在帮助下重定向到文件 SchemaExport Ant任务。
将hbm2ddl.auto
设置为none
(未记录)可能会生成警告,例如:org.hibernate.cfg.SettingsFactory - Unrecognized value for "hibernate.hbm2ddl.auto": none
答案 1 :(得分:34)
您可以通过以下方式将其关闭:
hibernate.hbm2ddl.auto=none
它没有证件但是无价!
答案 2 :(得分:11)
要明确这一点,应该查看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 );
}
在org.hibernate.cfg.Settings
类中,这些变量初始化为:
private boolean autoCreateSchema;
private boolean autoDropSchema;
private boolean autoUpdateSchema;
private boolean autoValidateSchema;
所以这些默认为false。
省略hibernate.hbm2ddl.auto
设置应该按照建议HBM2DDL_AUTO
关闭hibernate.hbm2ddl.auto = none
功能,但在后一种情况下,您会在日志中收到警告。
答案 3 :(得分:4)
在hibernate.properties
中hibernate.hbm2ddl.auto=validate
当然,配置它的地方取决于你配置你的休眠的方式 - 如果是以编程方式,在那里设置属性。如果是来自hibernate.cfg.xml:
<property name="hibernate.hbm2ddl.auto">validate</property>
答案 4 :(得分:3)
如果输入不受支持的值,它会告诉您支持哪些值:
o.h.b.i.SessionFactoryBuilderImpl : Unrecognized hbm2ddl_auto value : bla. Supported values include 'create', 'create-drop', 'update', 'none' and 'validate'. Ignoring
值none
是默认值,正式支持并记录在案:
https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl
答案 5 :(得分:0)
此属性不是必需的。只需从xml文件中完全删除import os
obs_dir = ['18185','18186','18187','19926','19987','19994','19995','20045','20046','20081']
xid = ['src21']
i=0
os.system("pset combine_spectra src_arfs=/"
+ obs_dir[0] + "/" + xid[i] + "_" + obs_dir[0] + "_spectrum.arf,"
+ "/" + obs_dir[1] + "/" + xid[i] + "_" + obs_dir[1] + "_spectrum.arf,"
+ "/" + obs_dir[2] + "/" + xid[i] + "_" + obs_dir[2] + "_spectrum.arf,"
+ "/" + obs_dir[3] + "/" + xid[i] + "_" + obs_dir[3] + "_spectrum.arf,"
+ "/" + obs_dir[4] + "/" + xid[i] + "_" + obs_dir[4] + "_spectrum.arf,"
+ "/" + obs_dir[5] + "/" + xid[i] + "_" + obs_dir[5] + "_spectrum.arf,"
+ "/" + obs_dir[6] + "/" + xid[i] + "_" + obs_dir[6] + "_spectrum.arf,"
+ "/" + obs_dir[7] + "/" + xid[i] + "_" + obs_dir[7] + "_spectrum.arf,"
+ "/" + obs_dir[8] + "/" + xid[i] + "_" + obs_dir[8] + "_spectrum.arf,"
+ "/" + obs_dir[9] + "/" + xid[i] + "_" + obs_dir[9] + "_spectrum.arf")
条目。