diff --git a/pom.xml b/pom.xml
index 0925107f18..e0cace7a5a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
> implements PersistentProperty
{
@@ -87,7 +89,7 @@ public AbstractPersistentProperty(Property property, PersistentEntity, P> owne
this.association = Lazy.of(() -> isAssociation() ? createAssociation() : null);
this.owner = owner;
- this.hashCode = Lazy.of(property::hashCode);
+ this.hashCode = Lazy.of(() -> Objects.hash(property, owner));
this.usePropertyAccess = Lazy.of(() -> owner.getType().isInterface() || CAUSE_FIELD.equals(getField()));
this.isAssociation = Lazy.of(() -> ASSOCIATION_TYPE != null && ASSOCIATION_TYPE.isAssignableFrom(rawType));
@@ -317,7 +319,7 @@ public boolean equals(@Nullable Object obj) {
return false;
}
- return this.property.equals(that.property);
+ return this.property.equals(that.property) && this.owner.equals(that.owner);
}
@Override
diff --git a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
index a15e63513b..13be98a563 100755
--- a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
+++ b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java
@@ -81,16 +81,6 @@ void isEntityWorksForUntypedCollection() {
assertThat(getProperty(TestClassComplex.class, "collection").isEntity()).isFalse();
}
- @Test // DATACMNS-121
- void considersPropertiesEqualIfFieldEquals() {
-
- var firstProperty = getProperty(FirstConcrete.class, "genericField");
- var secondProperty = getProperty(SecondConcrete.class, "genericField");
-
- assertThat(firstProperty).isEqualTo(secondProperty);
- assertThat(firstProperty.hashCode()).isEqualTo(secondProperty.hashCode());
- }
-
@Test // DATACMNS-180
void doesNotConsiderJavaTransientFieldsTransient() {
assertThat(getProperty(TestClassComplex.class, "transientField").isTransient()).isFalse();
@@ -207,7 +197,7 @@ void resolvesFieldNameWithUnderscoresCorrectly() {
@Test // DATACMNS-1139
void resolvesGenericsForRawType() {
- var property = getProperty(FirstConcrete.class, "genericField");
+ var property = getProperty(Concrete.class, "genericField");
assertThat(property.getRawType()).isEqualTo(String.class);
}
@@ -240,6 +230,15 @@ void considersVavrMaps() {
assertThat(property.isMap()).isTrue();
}
+ @Test // GH-2972
+ void equalsConsidersOwner() {
+
+ SamplePersistentProperty id1 = getProperty(Inherited1.class, "id");
+ SamplePersistentProperty id2 = getProperty(Inherited2.class, "id");
+
+ assertThat(id1).isNotEqualTo(id2);
+ }
+
private