8
8
9
9
import java .util .Collection ;
10
10
import java .util .Locale ;
11
+ import javax .persistence .EmbeddedId ;
11
12
import javax .persistence .Id ;
12
13
13
14
import javassist .CtClass ;
@@ -34,24 +35,15 @@ public String buildInLineDirtyCheckingBodyFragment(EnhancementContext context, C
34
35
final StringBuilder builder = new StringBuilder ();
35
36
try {
36
37
// should ignore primary keys
37
- if (PersistentAttributesHelper .hasAnnotation ( currentValue , Id .class ) ) {
38
+ if ( PersistentAttributesHelper .hasAnnotation ( currentValue , Id .class )
39
+ || PersistentAttributesHelper .hasAnnotation ( currentValue , EmbeddedId .class ) ) {
38
40
return "" ;
39
41
}
40
42
41
- // primitives || enums
42
43
if ( currentValue .getType ().isPrimitive () || currentValue .getType ().isEnum () ) {
44
+ // primitives || enums
43
45
builder .append ( String .format ( " if (%s != $1)" , currentValue .getName () ) );
44
46
}
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
55
47
else {
56
48
// if the field is a collection we return since we handle that in a separate method
57
49
for ( CtClass ctClass : currentValue .getType ().getInterfaces () ) {
@@ -62,9 +54,13 @@ else if ( currentValue.getType().getName().startsWith( "java.lang" )
62
54
}
63
55
}
64
56
}
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
+ );
68
64
}
69
65
builder .append ( String .format ( " { %s(\" %s\" ); }" , EnhancerConstants .TRACKER_CHANGER_NAME , currentValue .getName () ) );
70
66
}
0 commit comments