diff --git a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/config/HibernateConfig.java b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/config/HibernateConfig.java index ddd4f590c00f..c905728d2090 100644 --- a/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/config/HibernateConfig.java +++ b/dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/config/HibernateConfig.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.config; +import static org.hisp.dhis.external.conf.ConfigurationKey.CONNECTION_SCHEMA; import static org.hisp.dhis.external.conf.ConfigurationKey.USE_QUERY_CACHE; import static org.hisp.dhis.external.conf.ConfigurationKey.USE_SECOND_LEVEL_CACHE; @@ -137,7 +138,7 @@ public EntityManagerFactory entityManagerFactory( * @return TRUE if connection.schema is not set to none */ private boolean shouldGenerateDDL(DhisConfigurationProvider dhisConfig) { - return "update".equals(dhisConfig.getProperty(ConfigurationKey.CONNECTION_SCHEMA)); + return "update".equals(dhisConfig.getProperty(CONNECTION_SCHEMA)); } /** @@ -180,9 +181,7 @@ private Properties getAdditionalProperties(DhisConfigurationProvider dhisConfig) MissingCacheStrategy.CREATE.getExternalRepresentation()); } - properties.put( - AvailableSettings.HBM2DDL_AUTO, - Action.valueOf(dhisConfig.getProperty(ConfigurationKey.CONNECTION_SCHEMA).toUpperCase())); + properties.put(AvailableSettings.HBM2DDL_AUTO, getHibernateSchemaAction(dhisConfig)); properties.put( AvailableSettings.SHOW_SQL, dhisConfig.getProperty(ConfigurationKey.HIBERNATE_SHOW_SQL)); @@ -197,4 +196,16 @@ private Properties getAdditionalProperties(DhisConfigurationProvider dhisConfig) return properties; } + + private Action getHibernateSchemaAction(DhisConfigurationProvider dhisConfig) { + try { + return Action.interpretHbm2ddlSetting(dhisConfig.getProperty(CONNECTION_SCHEMA)); + } catch (Exception e) { + log.warn( + String.format( + "Invalid value for property connection.schema: %s. Using validate as default mode.", + dhisConfig.getProperty(CONNECTION_SCHEMA))); + return Action.VALIDATE; + } + } }