diff --git a/documentation/src/main/asciidoc/userguide/appendices/Configurations.adoc b/documentation/src/main/asciidoc/userguide/appendices/Configurations.adoc index 588ca08eaa..56501c176e 100644 --- a/documentation/src/main/asciidoc/userguide/appendices/Configurations.adoc +++ b/documentation/src/main/asciidoc/userguide/appendices/Configurations.adoc @@ -450,11 +450,11 @@ Note that the default serialization format of collections can differ depending o [[configurations-bytecode-enhancement]] === Bytecode Enhancement Properties -`*hibernate.enhancer.enableDirtyTracking*` (e.g. `true` or `false` (default value)):: -Enable dirty tracking feature in runtime bytecode enhancement. +`*hibernate.enhancer.enableDirtyTracking*` (e.g. `true` (default value) or `false`):: +Enable dirty tracking feature in runtime bytecode enhancement. This setting is deprecated for removal without a replacement. -`*hibernate.enhancer.enableLazyInitialization*` (e.g. `true` or `false` (default value)):: -Enable lazy loading feature in runtime bytecode enhancement. This way, even basic types (e.g. `@Basic(fetch = FetchType.LAZY`)) can be fetched lazily. +`*hibernate.enhancer.enableLazyInitialization*` (e.g. `true` (default value) or `false`):: +Enable lazy loading feature in runtime bytecode enhancement. This way, even basic types (e.g. `@Basic(fetch = FetchType.LAZY`)) can be fetched lazily. This setting is deprecated for removal without a replacement. `*hibernate.enhancer.enableAssociationManagement*` (e.g. `true` or `false` (default value)):: Enable association management feature in runtime bytecode enhancement which automatically synchronizes a bidirectional association when only one side is changed. diff --git a/documentation/src/main/asciidoc/userguide/chapters/tooling/enhancement.adoc b/documentation/src/main/asciidoc/userguide/chapters/tooling/enhancement.adoc index 15acfb873a..48a27036b2 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/tooling/enhancement.adoc +++ b/documentation/src/main/asciidoc/userguide/chapters/tooling/enhancement.adoc @@ -21,7 +21,7 @@ containers through `jakarta.persistence.spi.ClassTransformer`. See the document your container for any additional details. Run-time enhancement is controlled through 3 true/false settings (all of which default to false): -`hibernate.enhancer.enableDirtyTracking`:: Whether to enhance the model for dirty-tracking +`hibernate.enhancer.enableDirtyTracking`:: Whether to enhance the model for dirty-tracking. This setting is deprecated for removal without a replacement. `hibernate.enhancer.enableLazyInitialization`:: Whether to enhance the model for lazy loading at the attribute level. This allows -even basic types to be fetched lazily. It also allows definition of fetch groups (`LazyGroup`). +even basic types to be fetched lazily. It also allows definition of fetch groups (`LazyGroup`). This setting is deprecated for removal without a replacement. `hibernate.enhancer.enableAssociationManagement`:: Whether to automatically synchronize a bidirectional association when only one side is changed. diff --git a/documentation/src/main/asciidoc/userguide/chapters/tooling/gradle.adoc b/documentation/src/main/asciidoc/userguide/chapters/tooling/gradle.adoc index 4c560cf623..67bb95a5d0 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/tooling/gradle.adoc +++ b/documentation/src/main/asciidoc/userguide/chapters/tooling/gradle.adoc @@ -48,8 +48,8 @@ hibernate { The extension is of type `EnhancementSpec` which exposes the following properties: -enableLazyInitialization:: Whether to incorporate lazy loading support into the enhanced bytecode -enableDirtyTracking:: Whether to incorporate dirty tracking into the enhanced bytecode +enableLazyInitialization:: Whether to incorporate lazy loading support into the enhanced bytecode. Defaults to `true`. This setting is deprecated for removal without a replacement. +enableDirtyTracking:: Whether to incorporate dirty tracking into the enhanced bytecode. Defaults to `true`. This setting is deprecated for removal without a replacement. enableAssociationManagement:: Whether to add bidirectional association management into the enhanced bytecode diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/EnhancementContext.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/EnhancementContext.java index 83924ef4ca..c4f20cb40b 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/EnhancementContext.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/EnhancementContext.java @@ -75,7 +75,9 @@ public interface EnhancementContext { * * @return {@code true} indicates that dirty checking should be in-lined within the entity; {@code false} * indicates it should not. In-lined is more easily serializable and probably more performant. + * @deprecated Will be removed without replacement. See HHH-15641 */ + @Deprecated(forRemoval = true) boolean doDirtyCheckingInline(UnloadedClass classDescriptor); /** @@ -94,7 +96,9 @@ public interface EnhancementContext { * @param classDescriptor The class to check * * @return true/false + * @deprecated Will be removed without replacement. See HHH-15641 */ + @Deprecated(forRemoval = true) boolean hasLazyLoadableAttributes(UnloadedClass classDescriptor); // todo : may be better to invert these 2 such that the context is asked for an ordered list of persistent fields for an entity/composite 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 5c656e5747..852c16a634 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -2906,12 +2906,18 @@ public interface AvailableSettings { /** * Enable dirty tracking feature in runtime bytecode enhancement + * + * @deprecated Will be removed without replacement. See HHH-15641 */ + @Deprecated(forRemoval = true) String ENHANCER_ENABLE_DIRTY_TRACKING = "hibernate.enhancer.enableDirtyTracking"; /** * Enable lazy loading feature in runtime bytecode enhancement + * + * @deprecated Will be removed without replacement. See HHH-15641 */ + @Deprecated(forRemoval = true) String ENHANCER_ENABLE_LAZY_INITIALIZATION = "hibernate.enhancer.enableLazyInitialization"; /** 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 fa9e183357..9e9b2f5d47 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 @@ -255,4 +255,15 @@ public interface DeprecationLogger extends BasicLogger { ) void logDeprecatedHbmXmlProcessing(SourceType sourceType, String name); + /** + * Different from {@link #deprecatedSetting} in that sometimes there is no + * direct alternative + */ + @LogMessage(level = WARN) + @Message( + id = 90000029, + value = "The [%s] configuration is deprecated and will be removed. Set the value to [%s] to get rid of this warning" + ) + void deprecatedSettingForRemoval(String settingName, String defaultValue); + } diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java index b317d2854a..17753de746 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java @@ -305,9 +305,29 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // push back class transformation to the environment; for the time being this only has any effect in EE // container situations, calling back into PersistenceUnitInfo#addClassTransformer - final boolean dirtyTrackingEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING ); - final boolean lazyInitializationEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION ); + final boolean dirtyTrackingEnabled; + Object propertyValue = configurationValues.remove( AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING ); + if ( propertyValue != null ) { + dirtyTrackingEnabled = Boolean.parseBoolean( propertyValue.toString() ); + } + else { + dirtyTrackingEnabled = true; + } + final boolean lazyInitializationEnabled; + propertyValue = configurationValues.remove( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION ); + if ( propertyValue != null ) { + lazyInitializationEnabled = Boolean.parseBoolean( propertyValue.toString() ); + } + else { + lazyInitializationEnabled = true; + } final boolean associationManagementEnabled = readBooleanConfigurationValue( AvailableSettings.ENHANCER_ENABLE_ASSOCIATION_MANAGEMENT ); + if ( !lazyInitializationEnabled ) { + DEPRECATION_LOGGER.deprecatedSettingForRemoval( AvailableSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION, "true" ); + } + if ( !dirtyTrackingEnabled ) { + DEPRECATION_LOGGER.deprecatedSettingForRemoval( AvailableSettings.ENHANCER_ENABLE_DIRTY_TRACKING, "true" ); + } if ( dirtyTrackingEnabled || lazyInitializationEnabled || associationManagementEnabled ) { EnhancementContext enhancementContext = getEnhancementContext( diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/util/jpa/PersistenceUnitInfoAdapter.java b/hibernate-testing/src/main/java/org/hibernate/testing/util/jpa/PersistenceUnitInfoAdapter.java index 2e2bc9e038..752d97a4f4 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/util/jpa/PersistenceUnitInfoAdapter.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/util/jpa/PersistenceUnitInfoAdapter.java @@ -107,7 +107,6 @@ public class PersistenceUnitInfoAdapter implements PersistenceUnitInfo { @Override public void addTransformer(ClassTransformer transformer) { - throw new UnsupportedOperationException(); } @Override diff --git a/migration-guide.adoc b/migration-guide.adoc index a0de03a354..9cc672969d 100644 --- a/migration-guide.adoc +++ b/migration-guide.adoc @@ -88,3 +88,9 @@ The minimum supported dialect versions are as follows: |2.6.1 |=== +=== Change enhancement defaults and deprecation + +The `enableLazyInitialization` and `enableDirtyTracking` enhancement tooling options in the ANT task, Maven Plugin and Gradle Plugin, +as well as the respective `hibernate.enhancer.enableLazyInitialization` and `hibernate.enhancer.enableDirtyTracking` configuration settings, +switched their default values to `true` and the settings are now deprecated for removal without replacement. +See link:https://hibernate.atlassian.net/browse/HHH-15641[HHH-15641] for details. diff --git a/tooling/hibernate-ant/src/main/java/org/hibernate/tool/enhance/EnhancementTask.java b/tooling/hibernate-ant/src/main/java/org/hibernate/tool/enhance/EnhancementTask.java index 2f62a2286c..e5269a0a17 100644 --- a/tooling/hibernate-ant/src/main/java/org/hibernate/tool/enhance/EnhancementTask.java +++ b/tooling/hibernate-ant/src/main/java/org/hibernate/tool/enhance/EnhancementTask.java @@ -56,8 +56,8 @@ public class EnhancementTask extends Task { private String dir; private boolean failOnError = true; - private boolean enableLazyInitialization = false; - private boolean enableDirtyTracking = false; + private boolean enableLazyInitialization = true; + private boolean enableDirtyTracking = true; private boolean enableAssociationManagement = false; private boolean enableExtendedEnhancement = false; private List sourceSet = new ArrayList<>(); @@ -96,6 +96,12 @@ public class EnhancementTask extends Task { @Override public void execute() throws BuildException { + if ( !enableLazyInitialization ) { + log( "The 'enableLazyInitialization' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning", Project.MSG_WARN ); + } + if ( !enableDirtyTracking ) { + log( "The 'enableDirtyTracking' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning", Project.MSG_WARN ); + } if ( !shouldApply() ) { log( "Skipping Hibernate bytecode enhancement task execution since no feature is enabled", Project.MSG_WARN ); return; diff --git a/tooling/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/MavenEnhancePlugin.java b/tooling/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/MavenEnhancePlugin.java index b3249db77d..86e20d08ff 100644 --- a/tooling/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/MavenEnhancePlugin.java +++ b/tooling/hibernate-enhance-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/MavenEnhancePlugin.java @@ -68,10 +68,10 @@ public class MavenEnhancePlugin extends AbstractMojo { @Parameter(property = "failOnError", defaultValue = "true") private boolean failOnError = true; - @Parameter(property = "enableLazyInitialization", defaultValue = "false") + @Parameter(property = "enableLazyInitialization", defaultValue = "true") private boolean enableLazyInitialization; - @Parameter(property = "enableDirtyTracking", defaultValue = "false") + @Parameter(property = "enableDirtyTracking", defaultValue = "true") private boolean enableDirtyTracking; @Parameter(property = "enableAssociationManagement", defaultValue = "false") @@ -143,6 +143,12 @@ public class MavenEnhancePlugin extends AbstractMojo { } }; + if ( !enableLazyInitialization ) { + log.warn( "The 'enableLazyInitialization' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning" ); + } + if ( !enableDirtyTracking ) { + log.warn( "The 'enableDirtyTracking' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning" ); + } if ( enableExtendedEnhancement ) { log.warn( "Extended enhancement is enabled. Classes other than entities may be modified. You should consider access the entities using getter/setter methods and disable this property. Use at your own risk." ); } diff --git a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml b/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml index fa18073407..be774c652c 100644 --- a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml +++ b/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/org.hibernate.orm.tooling/hibernate-enhance-maven-plugin/plugin-help.xml @@ -57,14 +57,14 @@ java.lang.Boolean false true - Enable enhancement for lazy loading of attributes + DEPRECATED: Enable enhancement for lazy loading of attributes. This setting is deprecated for removal without a replacement. enableDirtyTracking java.lang.Boolean false true - Enable enhancement for tracking of dirty attributes + DEPRECATED: Enable enhancement for tracking of dirty attributes. This setting is deprecated for removal without a replacement. enableAssociationManagement diff --git a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml b/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml index 164317e31b..b484c318a5 100644 --- a/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml +++ b/tooling/hibernate-enhance-maven-plugin/src/main/resources/META-INF/maven/plugin.xml @@ -58,14 +58,14 @@ java.lang.Boolean false true - Enable enhancement for lazy loading of attributes + DEPRECATED: Enable enhancement for lazy loading of attributes. This setting is deprecated for removal without a replacement. enableDirtyTracking java.lang.Boolean false true - Enable enhancement for tracking of dirty attributes + DEPRECATED: Enable enhancement for tracking of dirty attributes. This setting is deprecated for removal without a replacement. enableAssociationManagement diff --git a/tooling/hibernate-gradle-plugin/src/main/java/org/hibernate/orm/tooling/gradle/enhance/EnhancementHelper.java b/tooling/hibernate-gradle-plugin/src/main/java/org/hibernate/orm/tooling/gradle/enhance/EnhancementHelper.java index 4af900eea4..e36f9a4398 100644 --- a/tooling/hibernate-gradle-plugin/src/main/java/org/hibernate/orm/tooling/gradle/enhance/EnhancementHelper.java +++ b/tooling/hibernate-gradle-plugin/src/main/java/org/hibernate/orm/tooling/gradle/enhance/EnhancementHelper.java @@ -39,6 +39,13 @@ public class EnhancementHelper { final Directory classesDirectory = classesDirectoryProperty.get(); final File classesDir = classesDirectory.getAsFile(); + final EnhancementSpec enhancementDsl = ormDsl.getEnhancement(); + if ( !enhancementDsl.getEnableLazyInitialization().get() ) { + project.getLogger().warn( "The 'enableLazyInitialization' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning" ); + } + if ( !enhancementDsl.getEnableDirtyTracking().get() ) { + project.getLogger().warn( "The 'enableDirtyTracking' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning" ); + } final Enhancer enhancer = generateEnhancer( classLoader, ormDsl ); walk( classesDir, classesDir, enhancer, project ); diff --git a/tooling/hibernate-gradle-plugin/src/main/java/org/hibernate/orm/tooling/gradle/enhance/EnhancementSpec.java b/tooling/hibernate-gradle-plugin/src/main/java/org/hibernate/orm/tooling/gradle/enhance/EnhancementSpec.java index 37cb074382..7572274c3d 100644 --- a/tooling/hibernate-gradle-plugin/src/main/java/org/hibernate/orm/tooling/gradle/enhance/EnhancementSpec.java +++ b/tooling/hibernate-gradle-plugin/src/main/java/org/hibernate/orm/tooling/gradle/enhance/EnhancementSpec.java @@ -34,8 +34,8 @@ public class EnhancementSpec { public EnhancementSpec(HibernateOrmSpec ormDsl, Project project) { final SourceSetContainer sourceSets = project.getExtensions().getByType( SourceSetContainer.class ); - enableLazyInitialization = makeProperty( project ); - enableDirtyTracking = makeProperty( project ); + enableLazyInitialization = makeProperty( project ).convention( true ); + enableDirtyTracking = makeProperty( project ).convention( true ); enableAssociationManagement = makeProperty( project ); enableExtendedEnhancement = makeProperty( project ); } @@ -47,43 +47,53 @@ public class EnhancementSpec { || enableExtendedEnhancement.get(); } + @Deprecated(forRemoval = true) public Property getEnableLazyInitialization() { return enableLazyInitialization; } + @Deprecated(forRemoval = true) public void setEnableLazyInitialization(boolean enable) { enableLazyInitialization.set( enable ); } + @Deprecated(forRemoval = true) public void enableLazyInitialization(boolean enable) { setEnableLazyInitialization( enable ); } + @Deprecated(forRemoval = true) public void lazyInitialization(boolean enable) { setEnableLazyInitialization( enable ); } + @Deprecated(forRemoval = true) public void setLazyInitialization(boolean enable) { setEnableLazyInitialization( enable ); } + @Deprecated(forRemoval = true) public Property getEnableDirtyTracking() { return enableDirtyTracking; } + @Deprecated(forRemoval = true) public void setEnableDirtyTracking(boolean enable) { enableDirtyTracking.set( enable ); } + @Deprecated(forRemoval = true) public void enableDirtyTracking(boolean enable) { setEnableDirtyTracking( enable ); } + @Deprecated(forRemoval = true) public void dirtyTracking(boolean enable) { setEnableDirtyTracking( enable ); } + @Deprecated(forRemoval = true) public void setDirtyTracking(boolean enable) { setEnableDirtyTracking( enable ); }