Skip to content

Commit 6ac234e

Browse files
barreirosebersole
authored andcommitted
HHH-9938 - field access parameter on gradle plugin
1 parent 088b15f commit 6ac234e

File tree

5 files changed

+15
-165
lines changed

5 files changed

+15
-165
lines changed

documentation/src/main/asciidoc/topical/bytecode/BytecodeEnhancement.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ hibernate {
7878
----
7979
====
8080

81-
Currently the "enhance" extension supports 3 properties:
81+
Currently the "enhance" extension supports 4 properties:
8282

8383
* `enableLazyInitialization`
8484
* `enableDirtyTracking`
8585
* `enableAssociationManagement`
86+
* `enableFieldAccessEnhancement`
8687

87-
Once enhancement overall is enabled, the default for these 3 properties is `true`.
88+
Once enhancement overall is enabled, the default for the first 3 properties is `true`. Field access is not enhanced by
89+
default, as it can potentially trigger enhancement of code outside the entities, and also because it assumes that all
90+
the target entities are enhanced, which may not always be the case.
8891

8992

9093
=== Ant Task

tooling/hibernate-gradle-plugin/src/main/groovy/org/hibernate/orm/tooling/gradle/EnhanceExtension.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class EnhanceExtension {
1616
def boolean enableLazyInitialization = true
1717
def boolean enableDirtyTracking = true
1818
def boolean enableAssociationManagement = true
19+
def boolean enableFieldAccessEnhancement = false
1920

2021
boolean shouldApply() {
21-
return enableLazyInitialization || enableDirtyTracking || enableAssociationManagement;
22+
return enableLazyInitialization || enableDirtyTracking || enableAssociationManagement || enableFieldAccessEnhancement;
2223
}
2324
}

tooling/hibernate-gradle-plugin/src/main/groovy/org/hibernate/orm/tooling/gradle/EnhancerTask.groovy

Lines changed: 0 additions & 159 deletions
This file was deleted.

tooling/hibernate-gradle-plugin/src/main/groovy/org/hibernate/orm/tooling/gradle/HibernatePlugin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public boolean hasLazyLoadableAttributes(CtClass classDescriptor) {
110110
public boolean isLazyLoadable(CtField field) {
111111
return hibernateExtension.enhance.getEnableLazyInitialization();
112112
}
113+
114+
@Override
115+
public boolean doFieldAccessEnhancement(CtClass classDescriptor) {
116+
return hibernateExtension.enhance.getEnableFieldAccessEnhancement();
117+
}
113118
};
114119

115120
final Enhancer enhancer = new Enhancer( enhancementContext );

tooling/hibernate-gradle-plugin/src/test/groovy/org/hibernate/orm/tooling/gradle/HibernatePluginTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
66
*/
77
package org.hibernate.orm.tooling.gradle
8-
98
import org.gradle.api.Project
109
import org.gradle.testfixtures.ProjectBuilder
1110

1211
import org.junit.Test
1312

1413
import static org.junit.Assert.assertNotNull
15-
import static org.junit.Assert.assertTrue
16-
1714
/**
1815
* Test what we can. ProjectBuilder is better than nothing, but still quited limited in what
1916
* you can test (e.g. you cannot test task execution).
@@ -35,7 +32,10 @@ class HibernatePluginTest {
3532
project.plugins.apply 'org.hibernate.orm'
3633

3734
project.extensions.findByType( HibernateExtension.class ).enhance {
35+
enableLazyInitialization = true
36+
enableDirtyTracking = true
3837
enableAssociationManagement = false
38+
enableFieldAccessEnhancement = false
3939
}
4040
}
4141
}

0 commit comments

Comments
 (0)