HHH-13226 Log a warning in case of inconsistent configuration properties

This commit is contained in:
Sanne Grinovero 2019-07-12 11:05:50 +01:00
parent d18b38c504
commit ee63e49011
2 changed files with 23 additions and 1 deletions

View File

@ -1866,4 +1866,9 @@ public interface CoreMessageLogger extends BasicLogger {
@LogMessage(level = WARN)
@Message(value = "A class should not be annotated with both @Inheritance and @MappedSuperclass. @Inheritance will be ignored for: %s.", id = 503)
void unsupportedMappedSuperclassWithEntityInheritance(String entityName);
@LogMessage(level = WARN)
@Message(value = "Multiple configuration properties defined to create schema. Choose at most one among 'javax.persistence.create-database-schemas', 'hibernate.hbm2ddl.create_namespaces', 'hibernate.hbm2dll.create_namespaces' (this last being deprecated).", id = 504)
void multipleSchemaCreationSettingsDefined();
}

View File

@ -17,6 +17,8 @@ import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.resource.transaction.spi.DdlTransactionIsolator;
import org.hibernate.service.ServiceRegistry;
@ -39,7 +41,8 @@ import org.jboss.logging.Logger;
* @author Steve Ebersole
*/
public class Helper {
private static final Logger log = Logger.getLogger( Helper.class );
private static final CoreMessageLogger log = CoreLogging.messageLogger( Helper.class );
public static ScriptSourceInput interpretScriptSourceSetting(
Object scriptSourceSetting,
@ -103,6 +106,20 @@ public class Helper {
}
public static boolean interpretNamespaceHandling(Map configurationValues) {
//Print a warning if multiple conflicting properties are being set:
int count = 0;
if ( configurationValues.containsKey( AvailableSettings.HBM2DDL_CREATE_SCHEMAS ) ) {
count++;
}
if ( configurationValues.containsKey( AvailableSettings.HBM2DDL_CREATE_NAMESPACES ) ) {
count++;
}
if ( configurationValues.containsKey( AvailableSettings.HBM2DLL_CREATE_NAMESPACES ) ) {
count++;
}
if ( count > 1 ) {
log.multipleSchemaCreationSettingsDefined();
}
// prefer the JPA setting...
return ConfigurationHelper.getBoolean(
AvailableSettings.HBM2DDL_CREATE_SCHEMAS,