diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/PersistentPropertyPathExtensionUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/PersistentPropertyPathExtensionUnitTests.java index 562d36690..be07ab8a6 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/PersistentPropertyPathExtensionUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/PersistentPropertyPathExtensionUnitTests.java @@ -200,6 +200,26 @@ public class PersistentPropertyPathExtensionUnitTests { }); } + @Test // GH--1164 + void equalsWorks() { + + PersistentPropertyPathExtension root1 = extPath(entity); + PersistentPropertyPathExtension root2 = extPath(entity); + PersistentPropertyPathExtension path1 = extPath("withId"); + PersistentPropertyPathExtension path2 = extPath("withId"); + + assertSoftly(softly -> { + + softly.assertThat(root1).describedAs("root is equal to self").isEqualTo(root1); + softly.assertThat(root2).describedAs("root is equal to identical root").isEqualTo(root1); + softly.assertThat(path1).describedAs("path is equal to self").isEqualTo(path1); + softly.assertThat(path2).describedAs("path is equal to identical path").isEqualTo(path1); + softly.assertThat(path1).describedAs("path is not equal to other path").isNotEqualTo(extPath("entityId")); + softly.assertThat(root1).describedAs("root is not equal to path").isNotEqualTo(path1); + softly.assertThat(path1).describedAs("path is not equal to root").isNotEqualTo(root1); + }); + } + private PersistentPropertyPathExtension extPath(RelationalPersistentEntity entity) { return new PersistentPropertyPathExtension(context, entity); } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java index e06ebcdbe..2c5b19f0a 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java @@ -442,7 +442,7 @@ public class PersistentPropertyPathExtension { if (o == null || getClass() != o.getClass()) return false; PersistentPropertyPathExtension that = (PersistentPropertyPathExtension) o; return entity.equals(that.entity) && - path.equals(that.path); + Objects.equals(path, that.path); } @Override