diff --git a/hibernate-core/src/main/java/org/hibernate/EntityMode.java b/hibernate-core/src/main/java/org/hibernate/EntityMode.java index 1f07ca88d4..522a333e34 100644 --- a/hibernate-core/src/main/java/org/hibernate/EntityMode.java +++ b/hibernate-core/src/main/java/org/hibernate/EntityMode.java @@ -8,11 +8,16 @@ package org.hibernate; import java.util.Locale; +import static org.hibernate.cfg.AvailableSettings.DEFAULT_ENTITY_MODE; +import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; + /** * Defines the representation modes available for entities. * - * @author Steve Ebersole + * @deprecated To be removed in 6.0 in favor of `ManagedTypeRepresentationStrategy` + * and `RepresentationMode` */ +@Deprecated public enum EntityMode { /** * The {@code pojo} entity mode describes an entity model made up of entity classes (loosely) following @@ -58,4 +63,23 @@ public enum EntityMode { return valueOf( entityMode.toUpperCase( Locale.ENGLISH ) ); } + public static EntityMode fromSetting(Object setting) { + if ( setting != null ) { + DEPRECATION_LOGGER.deprecatedSetting( DEFAULT_ENTITY_MODE ); + } + + if ( setting == null || setting == POJO ) { + return POJO; + } + + if ( setting instanceof EntityMode ) { + return ( (EntityMode) setting ); + } + + if ( setting instanceof String ) { + return parse( (String) setting ); + } + + return POJO; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java index ac6163fdfa..d0b4376af5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java @@ -130,6 +130,7 @@ import static org.hibernate.cfg.AvailableSettings.WRAP_RESULT_SETS; import static org.hibernate.cfg.AvailableSettings.DISCARD_PC_ON_CLOSE; import static org.hibernate.engine.config.spi.StandardConverters.BOOLEAN; import static org.hibernate.internal.CoreLogging.messageLogger; +import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; /** * In-flight state of {@link org.hibernate.boot.spi.SessionFactoryOptions} @@ -330,10 +331,11 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { this.entityNotFoundDelegate = StandardEntityNotFoundDelegate.INSTANCE; this.identifierRollbackEnabled = cfgService.getSetting( USE_IDENTIFIER_ROLLBACK, BOOLEAN, false ); - this.defaultEntityMode = EntityMode.parse( (String) configurationSettings.get( DEFAULT_ENTITY_MODE ) ); this.checkNullability = cfgService.getSetting( CHECK_NULLABILITY, BOOLEAN, true ); this.initializeLazyStateOutsideTransactions = cfgService.getSetting( ENABLE_LAZY_LOAD_NO_TRANS, BOOLEAN, false ); + this.defaultEntityMode = EntityMode.fromSetting( configurationSettings.get( DEFAULT_ENTITY_MODE ) ); + this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configurationSettings ); this.currentTenantIdentifierResolver = strategySelector.resolveStrategy( CurrentTenantIdentifierResolver.class, @@ -475,7 +477,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { null ); if ( oldSetting != null ) { - DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting( + DEPRECATION_LOGGER.deprecatedSetting( org.hibernate.jpa.AvailableSettings.DISCARD_PC_ON_CLOSE, DISCARD_PC_ON_CLOSE ); @@ -562,7 +564,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { () -> { final Object oldSetting = configurationSettings.get( org.hibernate.jpa.AvailableSettings.INTERCEPTOR ); if ( oldSetting != null ) { - DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting( + DEPRECATION_LOGGER.deprecatedSetting( org.hibernate.jpa.AvailableSettings.INTERCEPTOR, INTERCEPTOR ); @@ -583,7 +585,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { () -> { final Object oldSetting = configurationSettings.get( org.hibernate.jpa.AvailableSettings.SESSION_INTERCEPTOR ); if ( oldSetting != null ) { - DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting( + DEPRECATION_LOGGER.deprecatedSetting( org.hibernate.jpa.AvailableSettings.SESSION_INTERCEPTOR, SESSION_SCOPED_INTERCEPTOR ); @@ -659,7 +661,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { ConnectionReleaseMode specifiedReleaseMode, Map configurationSettings, TransactionCoordinatorBuilder transactionCoordinatorBuilder) { - DeprecationLogger.DEPRECATION_LOGGER.logUseOfDeprecatedConnectionHandlingSettings(); + DEPRECATION_LOGGER.logUseOfDeprecatedConnectionHandlingSettings(); final ConnectionAcquisitionMode effectiveAcquisitionMode = specifiedAcquisitionMode == null ? ConnectionAcquisitionMode.AS_NEEDED diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/internal/EntityModeConverter.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/internal/EntityModeConverter.java index d9548064fa..6c5aa1ad1b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/internal/EntityModeConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/internal/EntityModeConverter.java @@ -7,16 +7,31 @@ package org.hibernate.boot.jaxb.hbm.internal; import org.hibernate.EntityMode; +import org.hibernate.internal.log.DeprecationLogger; +import org.hibernate.internal.util.StringHelper; /** - * @author Steve Ebersole + * @deprecated for removal in 6.0 */ +@Deprecated public class EntityModeConverter { public static EntityMode fromXml(String name) { - return EntityMode.parse( name ); + final EntityMode entityMode = EntityMode.parse( name ); + if ( StringHelper.isNotEmpty( name ) ) { + DeprecationLogger.DEPRECATION_LOGGER.info( + "XML mapping specified an entity-mode - `%s`. Starting in 6.0 this is simply inferred from the entity/composite mapping" + ); + } + return entityMode; } public static String toXml(EntityMode entityMode) { - return ( null == entityMode ) ? null : entityMode.getExternalName(); + if ( entityMode == null ) { + return null; + } + DeprecationLogger.DEPRECATION_LOGGER.info( + "XML mapping specified an entity-mode - `%s`. Starting in 6.0 this is simply inferred from the entity/composite mapping" + ); + return entityMode.getExternalName(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java index cfb2826243..230856c212 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java @@ -324,10 +324,22 @@ public abstract class AbstractEntitySourceImpl return jaxbEntityMapping.isSelectBeforeUpdate(); } + /** + * @deprecated to be removed in 6.0. Starting in 6.0 the mode is inferred + * from the entity-type mapping + */ + @Deprecated protected EntityMode determineEntityMode() { return StringHelper.isNotEmpty( entityNamingSource.getClassName() ) ? EntityMode.POJO : EntityMode.MAP; } + /** + * @deprecated to be removed in 6.0. Starting in 6.0 the mode is inferred + * from the entity-type mapping + * + * See `ManagedTypeRepresentationStrategy` and `RepresentationMode` in 6.0 + */ + @Deprecated @Override public Map getTuplizerClassMap() { return tuplizerClassMap; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index f4da85d681..59d79cb715 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -1409,7 +1409,10 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings { /** * The EntityMode in which set the Session opened from the SessionFactory. + * + * @deprecated An entity-type has one "mode" relative to any SessionFactory. */ + @Deprecated String DEFAULT_ENTITY_MODE = "hibernate.default_entity_mode"; /** diff --git a/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java index 9ecfe081bf..9f709d59a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java @@ -297,4 +297,10 @@ public interface DeprecationLogger extends BasicLogger { ) void deprecatedJmxBeanRegistration(String name); + @LogMessage(level = WARN) + @Message( + id = 90000031, + value = "Encountered deprecated setting [%s] which is planned for removal" + ) + void deprecatedSetting(String setting); }