@@ -53,7 +53,39 @@ public Change[] fixChanged(DatabaseObject changedObject, ObjectDifferences diffe
53
53
.filter (differenceField -> !HIBERNATE_SEQUENCE_FIELDS .contains (differenceField ))
54
54
.collect (Collectors .toCollection (LinkedHashSet ::new ));
55
55
ignoredDifferenceFields .forEach (differences ::removeDifference );
56
+ this .advancedIgnoredDifferenceFields (differences , referenceDatabase , comparisonDatabase );
56
57
return super .fixChanged (changedObject , differences , control , referenceDatabase , comparisonDatabase , chain );
57
58
}
58
59
60
+
61
+ /**
62
+ * In some cases a value that was 1 can be null in the database, or the name field can be different only by case.
63
+ * This method removes these differences from the list of differences so we don't generate a change for them.
64
+ */
65
+ private void advancedIgnoredDifferenceFields (ObjectDifferences differences , Database referenceDatabase , Database comparisonDatabase ) {
66
+ Set <String > ignoredDifferenceFields = new HashSet <>();
67
+ for (Difference difference : differences .getDifferences ()) {
68
+ String field = difference .getField ();
69
+ String refValue = difference .getReferenceValue () != null ? difference .getReferenceValue ().toString () : null ;
70
+ String comparedValue = difference .getComparedValue () != null ? difference .getComparedValue ().toString () : null ;
71
+
72
+ // if the name field case is different and the databases are case-insensitive, we can ignore the difference
73
+ boolean isNameField = field .equals ("name" );
74
+ boolean isCaseInsensitive = !referenceDatabase .isCaseSensitive () || !comparisonDatabase .isCaseSensitive ();
75
+
76
+ // if the startValue or incrementBy fields are 1 and the other is null, we can ignore the difference
77
+ // Or 50, as it is the default value for hibernate for allocationSize:
78
+ // https://github.com/hibernate/hibernate-orm/blob/bda95dfbe75c68f5c1b77a2f21c403cbe08548a2/hibernate-core/src/main/java/org/hibernate/boot/model/IdentifierGeneratorDefinition.java#L252
79
+ boolean isStartOrIncrementField = field .equals ("startValue" ) || field .equals ("incrementBy" );
80
+ boolean isOneOrFiftyAndNull = "1" .equals (refValue ) && comparedValue == null || refValue == null && "1" .equals (comparedValue ) ||
81
+ "50" .equals (refValue ) && comparedValue == null || refValue == null && "50" .equals (comparedValue );
82
+
83
+ if ((isNameField && isCaseInsensitive && refValue != null && refValue .equalsIgnoreCase (comparedValue )) ||
84
+ (isStartOrIncrementField && isOneOrFiftyAndNull )) {
85
+ ignoredDifferenceFields .add (field );
86
+ }
87
+ }
88
+ ignoredDifferenceFields .forEach (differences ::removeDifference );
89
+ }
90
+
59
91
}
0 commit comments