Skip to content

Commit 9d2b106

Browse files
committed
HHH-10020 - Improvements to org.hibernate.bytecode.enhance.internal.AttributeTypeDescriptor#buildInLineDirtyCheckingBodyFragment
(cherry picked from commit 1c70e0d)
1 parent 74bfdd9 commit 9d2b106

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.util.Collection;
1010
import java.util.Locale;
11+
import javax.persistence.EmbeddedId;
1112
import javax.persistence.Id;
1213

1314
import javassist.CtClass;
@@ -34,24 +35,15 @@ public String buildInLineDirtyCheckingBodyFragment(EnhancementContext context, C
3435
final StringBuilder builder = new StringBuilder();
3536
try {
3637
// should ignore primary keys
37-
if (PersistentAttributesHelper.hasAnnotation( currentValue, Id.class ) ) {
38+
if ( PersistentAttributesHelper.hasAnnotation( currentValue, Id.class )
39+
|| PersistentAttributesHelper.hasAnnotation( currentValue, EmbeddedId.class ) ) {
3840
return "";
3941
}
4042

41-
// primitives || enums
4243
if ( currentValue.getType().isPrimitive() || currentValue.getType().isEnum() ) {
44+
// primitives || enums
4345
builder.append( String.format( " if (%s != $1)", currentValue.getName() ) );
4446
}
45-
// simple data types
46-
else if ( currentValue.getType().getName().startsWith( "java.lang" )
47-
|| currentValue.getType().getName().startsWith( "java.math.Big" )
48-
|| currentValue.getType().getName().startsWith( "java.sql.Time" )
49-
|| currentValue.getType().getName().startsWith( "java.sql.Date" )
50-
|| currentValue.getType().getName().startsWith( "java.util.Date" )
51-
|| currentValue.getType().getName().startsWith( "java.util.Calendar" ) ) {
52-
builder.append( String.format( " if (%s == null || !%<s.equals($1))", currentValue.getName() ) );
53-
}
54-
// all other objects
5547
else {
5648
// if the field is a collection we return since we handle that in a separate method
5749
for ( CtClass ctClass : currentValue.getType().getInterfaces() ) {
@@ -62,9 +54,13 @@ else if ( currentValue.getType().getName().startsWith( "java.lang" )
6254
}
6355
}
6456
}
65-
builder.append( String.format( " if (%1$s == null || !%2$s.equals(%1$s, $1))",
66-
currentValue.getName(),
67-
EqualsHelper.class.getName() ) );
57+
builder.append(
58+
String.format(
59+
" if ( !%s.areEqual( %s, $1 ) )",
60+
EqualsHelper.class.getName(),
61+
currentValue.getName()
62+
)
63+
);
6864
}
6965
builder.append( String.format( " { %s(\"%s\"); }", EnhancerConstants.TRACKER_CHANGER_NAME, currentValue.getName() ) );
7066
}

0 commit comments

Comments
 (0)