Skip to content

Commit 0c9f477

Browse files
committed
Revert "AbstractPersistentProperty now considers the owner for equals."
This reverts commit 93913b0. The change caused build failures for Spring Data JDBC. See #2972 Original pull request #2973 See spring-projects/spring-data-relational#1657
1 parent a3f4ac6 commit 0c9f477

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.lang.reflect.Modifier;
2121
import java.util.Collections;
2222
import java.util.HashSet;
23-
import java.util.Objects;
2423
import java.util.Optional;
2524
import java.util.Set;
2625
import java.util.stream.Collectors;
@@ -41,7 +40,6 @@
4140
* @author Oliver Gierke
4241
* @author Christoph Strobl
4342
* @author Mark Paluch
44-
* @author Jens Schauder
4543
*/
4644
public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>> implements PersistentProperty<P> {
4745

@@ -87,7 +85,7 @@ public AbstractPersistentProperty(Property property, PersistentEntity<?, P> owne
8785
this.association = Lazy.of(() -> isAssociation() ? createAssociation() : null);
8886
this.owner = owner;
8987

90-
this.hashCode = Lazy.of(() -> Objects.hash(property, owner));
88+
this.hashCode = Lazy.of(property::hashCode);
9189
this.usePropertyAccess = Lazy.of(() -> owner.getType().isInterface() || CAUSE_FIELD.equals(getField()));
9290

9391
this.isAssociation = Lazy.of(() -> ASSOCIATION_TYPE != null && ASSOCIATION_TYPE.isAssignableFrom(rawType));
@@ -295,7 +293,7 @@ public boolean equals(@Nullable Object obj) {
295293
return false;
296294
}
297295

298-
return this.property.equals(that.property) && this.owner.equals(that.owner);
296+
return this.property.equals(that.property);
299297
}
300298

301299
@Override

src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ void isEntityWorksForUntypedCollection() {
8484
assertThat(getProperty(TestClassComplex.class, "collection").isEntity()).isFalse();
8585
}
8686

87+
@Test // DATACMNS-121
88+
void considersPropertiesEqualIfFieldEquals() {
89+
90+
var firstProperty = getProperty(FirstConcrete.class, "genericField");
91+
var secondProperty = getProperty(SecondConcrete.class, "genericField");
92+
93+
assertThat(firstProperty).isEqualTo(secondProperty);
94+
assertThat(firstProperty.hashCode()).isEqualTo(secondProperty.hashCode());
95+
}
96+
8797
@Test // DATACMNS-180
8898
void doesNotConsiderJavaTransientFieldsTransient() {
8999
assertThat(getProperty(TestClassComplex.class, "transientField").isTransient()).isFalse();
@@ -200,7 +210,7 @@ void resolvesFieldNameWithUnderscoresCorrectly() {
200210
@Test // DATACMNS-1139
201211
void resolvesGenericsForRawType() {
202212

203-
var property = getProperty(Concrete.class, "genericField");
213+
var property = getProperty(FirstConcrete.class, "genericField");
204214

205215
assertThat(property.getRawType()).isEqualTo(String.class);
206216
}
@@ -233,15 +243,6 @@ void considersVavrMaps() {
233243
assertThat(property.isMap()).isTrue();
234244
}
235245

236-
@Test // GH-2972
237-
void equalsConsidersOwner() {
238-
239-
SamplePersistentProperty id1 = getProperty(Inherited1.class, "id");
240-
SamplePersistentProperty id2 = getProperty(Inherited2.class, "id");
241-
242-
assertThat(id1).isNotEqualTo(id2);
243-
}
244-
245246
private <T> BasicPersistentEntity<T, SamplePersistentProperty> getEntity(Class<T> type) {
246247
return new BasicPersistentEntity<>(TypeInformation.of(type));
247248
}
@@ -279,7 +280,11 @@ class Generic<T> {
279280

280281
}
281282

282-
class Concrete extends Generic<String> {
283+
class FirstConcrete extends Generic<String> {
284+
285+
}
286+
287+
class SecondConcrete extends Generic<Integer> {
283288

284289
}
285290

@@ -404,15 +409,4 @@ interface JMoleculesAggregate extends AggregateRoot<JMoleculesAggregate, Identif
404409
class VavrWrapper {
405410
io.vavr.collection.Map<String, String> vavrMap;
406411
}
407-
408-
class Base {
409-
Long id;
410-
}
411-
412-
class Inherited1 extends Base {
413-
}
414-
415-
class Inherited2 extends Base {
416-
}
417-
418412
}

0 commit comments

Comments
 (0)