Skip to content

Commit 1078caa

Browse files
committed
HHH-16049 Setting a property to its current value with bytecode enhancement enabled results in unnecessary SQL Update in some (many) cases
1 parent 802fc76 commit 1078caa

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/InlineDirtyCheckerEqualsHelper.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static boolean areEquals(
2020
Object b) {
2121
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
2222
if ( persistentAttributeInterceptor != null
23-
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
23+
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
2424
return false;
2525
}
2626
return Objects.deepEquals( a, b );
@@ -33,7 +33,7 @@ public static boolean areEquals(
3333
boolean b) {
3434
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
3535
if ( persistentAttributeInterceptor != null
36-
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
36+
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
3737
return false;
3838
}
3939
return a == b;
@@ -46,7 +46,7 @@ public static boolean areEquals(
4646
byte b) {
4747
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
4848
if ( persistentAttributeInterceptor != null
49-
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
49+
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
5050
return false;
5151
}
5252
return a == b;
@@ -59,7 +59,7 @@ public static boolean areEquals(
5959
short b) {
6060
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
6161
if ( persistentAttributeInterceptor != null
62-
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
62+
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
6363
return false;
6464
}
6565
return a == b;
@@ -72,7 +72,7 @@ public static boolean areEquals(
7272
char b) {
7373
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
7474
if ( persistentAttributeInterceptor != null
75-
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
75+
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
7676
return false;
7777
}
7878
return a == b;
@@ -85,7 +85,7 @@ public static boolean areEquals(
8585
int b) {
8686
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
8787
if ( persistentAttributeInterceptor != null
88-
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
88+
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
8989
return false;
9090
}
9191
return a == b;
@@ -98,7 +98,7 @@ public static boolean areEquals(
9898
long b) {
9999
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
100100
if ( persistentAttributeInterceptor != null
101-
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
101+
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
102102
return false;
103103
}
104104
return a == b;
@@ -111,7 +111,7 @@ public static boolean areEquals(
111111
float b) {
112112
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
113113
if ( persistentAttributeInterceptor != null
114-
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
114+
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
115115
return false;
116116
}
117117
return a == b;
@@ -124,7 +124,7 @@ public static boolean areEquals(
124124
double b) {
125125
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
126126
if ( persistentAttributeInterceptor != null
127-
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
127+
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
128128
return false;
129129
}
130130
return a == b;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public interface BytecodeLazyAttributeInterceptor extends SessionAssociableInter
3636
*/
3737
void attributeInitialized(String name);
3838

39+
@Override
3940
boolean isAttributeLoaded(String fieldName);
4041

4142
boolean hasAnyUninitializedAttributes();

hibernate-core/src/main/java/org/hibernate/engine/spi/PersistentAttributeInterceptor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,19 @@ default Set<String> getInitializedLazyAttributeNames() {
7878
@Deprecated
7979
default void attributeInitialized(String name) {
8080
}
81+
82+
/**
83+
*
84+
* Callback from the enhanced class that an attribute has been loaded
85+
*
86+
* @deprecated Interceptors that deal with
87+
* * lazy state should implement {@link BytecodeLazyAttributeInterceptor}
88+
*
89+
* @param fieldName
90+
* @return true id the attribute is loaded false otherwise
91+
*/
92+
@Deprecated
93+
default boolean isAttributeLoaded(String fieldName){
94+
return false;
95+
}
8196
}

0 commit comments

Comments
 (0)