88
99import java .util .Collection ;
1010import java .util .Locale ;
11+ import javax .persistence .EmbeddedId ;
1112import javax .persistence .Id ;
1213
1314import 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