HHH-15641 Enable inlineDirtyChecking and lazyLoading for enhancement by default and deprecate the setting

This commit is contained in:
Christian Beikov 2022-11-02 11:44:53 +01:00
parent c1e1b58e57
commit 0b733d4ba2
15 changed files with 96 additions and 21 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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";
/**

View File

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

View File

@ -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(

View File

@ -107,7 +107,6 @@ public class PersistenceUnitInfoAdapter implements PersistenceUnitInfo {
@Override
public void addTransformer(ClassTransformer transformer) {
throw new UnsupportedOperationException();
}
@Override

View File

@ -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.

View File

@ -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<File> 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;

View File

@ -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." );
}

View File

@ -57,14 +57,14 @@
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Enable enhancement for lazy loading of attributes</description>
<description>DEPRECATED: Enable enhancement for lazy loading of attributes. This setting is deprecated for removal without a replacement.</description>
</parameter>
<parameter>
<name>enableDirtyTracking</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Enable enhancement for tracking of dirty attributes</description>
<description>DEPRECATED: Enable enhancement for tracking of dirty attributes. This setting is deprecated for removal without a replacement.</description>
</parameter>
<parameter>
<name>enableAssociationManagement</name>

View File

@ -58,14 +58,14 @@
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Enable enhancement for lazy loading of attributes</description>
<description>DEPRECATED: Enable enhancement for lazy loading of attributes. This setting is deprecated for removal without a replacement.</description>
</parameter>
<parameter>
<name>enableDirtyTracking</name>
<type>java.lang.Boolean</type>
<required>false</required>
<editable>true</editable>
<description>Enable enhancement for tracking of dirty attributes</description>
<description>DEPRECATED: Enable enhancement for tracking of dirty attributes. This setting is deprecated for removal without a replacement.</description>
</parameter>
<parameter>
<name>enableAssociationManagement</name>

View File

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

View File

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