Skip to content

Commit c10579c

Browse files
committed
HHH-19661 - Deprecate enhancement support for "extended" enhancement
Signed-off-by: Jan Schatteman <[email protected]>
1 parent 0930fb3 commit c10579c

File tree

7 files changed

+21
-2
lines changed

7 files changed

+21
-2
lines changed

documentation/src/main/asciidoc/introduction/Advanced.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,10 @@ Interception is able to detect writes to the `image` field, that is, replacement
10551055
It's not able to detect modifications made directly to the _elements_ of the array, and so such modifications may be lost.
10561056
====
10571057

1058+
[IMPORTANT]
1059+
Hibernate's extended bytecode enhancement feature has been deprecated, primarily because it relies on assumptions and behaviors that often require a broader runtime scope than what Hibernate alone can reliably provide, similar to container-based environments such as Quarkus or WildFly.
1060+
Applications which make use of this feature should instead use proper object-oriented encapsulation, exposing managed state via getters and setters.
1061+
10581062
[[fetch-profiles]]
10591063
=== Named fetch profiles
10601064

documentation/src/main/asciidoc/userguide/chapters/domain/collections.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Hibernate is able to map Object and primitive arrays as collections. Mapping an
308308
the same as mapping a <<collection-list,list>>.
309309

310310
There is a major limitation of mapping arrays to be aware of - the array cannot be lazy using
311-
<<collection-wrapper,wrappers>>. It can, however, be lazy via <<bytecode-enhancement-guide,bytecode enhancement>>
311+
<<collection-wrapper,wrappers>>. It can, however, be lazy via <<chapters/pc/BytecodeEnhancement.adoc#BytecodeEnhancement, bytecode enhancement>>
312312
of its owner.
313313

314314
Note that Jakarta Persistence does not define support for arrays as plural attributes; according to the specification,

documentation/src/main/asciidoc/userguide/chapters/pc/BytecodeEnhancement.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ If your application does not need to care about "internal state changing data-ty
5858
In this approach Hibernate will manipulate the bytecode of your classes to add "dirty tracking" directly to the entity, allowing the entity itself to keep track of which of its attributes have changed.
5959
During the flush time, Hibernate asks your entity what has changed rather than having to perform the state-diff calculations.
6060

61+
[IMPORTANT]
62+
Hibernate's extended bytecode enhancement feature has been deprecated, primarily because it relies on assumptions and behaviors that often require a broader runtime scope than what Hibernate alone can reliably provide, similar to container-based environments such as Quarkus or WildFly.
63+
Applications which make use of this feature should instead use proper object-oriented encapsulation, exposing managed state via getters and setters.
64+
6165
[[BytecodeEnhancement-dirty-tracking-bidirectional]]
6266
==== Bidirectional association management
6367

hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/EnhancementContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ public interface EnhancementContext {
9090
*
9191
* @return {@code true} indicates that any direct access to fields of entities should be routed to the enhanced
9292
* getter / setter method.
93+
* @deprecated Will be removed without replacement. See HHH-19661
9394
*/
95+
@Deprecated(forRemoval = true)
9496
boolean doExtendedEnhancement(UnloadedClass classDescriptor);
9597

9698
/**

tooling/hibernate-ant/src/main/java/org/hibernate/tool/enhance/EnhancementTask.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333

3434
import static org.hibernate.bytecode.internal.BytecodeProviderInitiator.buildDefaultBytecodeProvider;
35+
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
3536

3637
/**
3738
* Ant task for performing build-time enhancement of entity objects.
@@ -200,7 +201,7 @@ public boolean doExtendedEnhancement(UnloadedClass classDescriptor) {
200201
};
201202

202203
if ( enableExtendedEnhancement ) {
203-
log( "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.", Project.MSG_WARN );
204+
DEPRECATION_LOGGER.deprecatedSettingForRemoval("extended enhancement", "false");
204205
}
205206

206207
final BytecodeProvider bytecodeProvider = buildDefaultBytecodeProvider();

tooling/hibernate-gradle-plugin/src/main/java/org/hibernate/orm/tooling/gradle/enhance/EnhancementHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ public static void enhance(
5050
if ( !enhancementDsl.getEnableDirtyTracking().get() ) {
5151
logger.warn( "The 'enableDirtyTracking' configuration is deprecated and will be removed. Set the value to 'true' to get rid of this warning" );
5252
}
53+
if ( enhancementDsl.getEnableExtendedEnhancement().get() ) {
54+
logger.warn("Extended enhancement is deprecated and will be removed. Set the value to 'false' to get rid of this warning" );
55+
}
5356
final Enhancer enhancer = generateEnhancer( classLoader, enhancementDsl );
5457

5558
discoverTypes( classesDir, classesDir, enhancer, ormDsl.getFileOperations() );

tooling/hibernate-maven-plugin/src/main/java/org/hibernate/orm/tooling/maven/EnhancementContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.hibernate.bytecode.enhance.spi.UnloadedClass;
99
import org.hibernate.bytecode.enhance.spi.UnloadedField;
1010

11+
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
12+
1113
public class EnhancementContext extends DefaultEnhancementContext {
1214

1315
private ClassLoader classLoader = null;
@@ -56,6 +58,9 @@ public boolean isLazyLoadable(UnloadedField field) {
5658

5759
@Override
5860
public boolean doExtendedEnhancement(UnloadedClass classDescriptor) {
61+
if (enableExtendedEnhancement) {
62+
DEPRECATION_LOGGER.deprecatedSettingForRemoval("extended enhancement", "false");
63+
}
5964
return enableExtendedEnhancement;
6065
}
6166

0 commit comments

Comments
 (0)