Jak wyłączyć hbm2ddl?

Nie mogłem znaleźć odniesienia, jak wyłączyć hbm2ddl.

Author: Ed Brannin, 2010-07-05

6 answers

Po prostu pominięcie hibernate.hbm2ddl.auto domyślnie Hibernate nic nie robi. Z dokumentacji referencyjnej:

1.1.4. Konfiguracja Hibernate

Opcja hbm2ddl.auto włącza się automatyczne generowanie bazy danych Schematy bezpośrednio do bazy danych. można to również wyłączyć, usuwając opcję konfiguracyjną , lub przekierowanie do pliku z pomocą SchemaExport Ant task.

Ustawienie hbm2ddl.auto na none (nieudokumentowane) może Wygeneruj Ostrzeżenie, takie jak: org.hibernate.cfg.SettingsFactory - Unrecognized value for "hibernate.hbm2ddl.auto": none

 69
Author: Pascal Thivent,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-21 01:52:46

Możesz go wyłączyć przez:

hibernate.hbm2ddl.auto=none
Jest nieudokumentowana, ale bezcenna !
 27
Author: Julien BRENELIERE,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-04 11:54:44

Aby to wyjaśnić, należy zajrzeć do źródła org.hibernate.cfg.SettingsFactory (możesz zobaczyć coś innego w zależności od użytej wersji):

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 );
}

W klasie org.hibernate.cfg.Settings zmienne te są inicjalizowane jako:

private boolean autoCreateSchema;
private boolean autoDropSchema;
private boolean autoUpdateSchema;
private boolean autoValidateSchema;

Więc te domyślnie false.

Pominięcie ustawienia hibernate.hbm2ddl.auto powinno wyłączyć funkcjonalność HBM2DDL_AUTO zgodnie z sugestią hibernate.hbm2ddl.auto = none, ale w tym drugim przypadku pojawia się ostrzeżenie w dzienniku.

 9
Author: Andres Saaremõts,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-10-15 12:26:43

W hibernacji.właściwości

hibernate.hbm2ddl.auto=validate

Oczywiście, miejsce jej konfiguracji zależy od sposobu konfiguracji hibernate - jeśli jest programowo, ustaw tam właściwość. Jeśli pochodzi z hibernate.cfg.xml:

<property name="hibernate.hbm2ddl.auto">validate</property>
 4
Author: Bozho,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-07-05 13:29:08

Ta właściwość nie jest wymagana. Wystarczy całkowicie usunąć wpis hibernate.hbm2ddl.auto z pliku xml.

 0
Author: gdrt,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-23 11:01:34

Jeśli wpiszesz nieobsługiwaną wartość, powie Ci, które z nich są obsługiwane: o.h.b.i.SessionFactoryBuilderImpl : Unrecognized hbm2ddl_auto value : bla. Supported values include 'create', 'create-drop', 'update', 'none' and 'validate'. Ignoring

I wartość none jest domyślna, jest oficjalnie obsługiwana i udokumentowana: https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl

 0
Author: jstadler,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-04-24 07:06:57