Revert "AbstractPersistentProperty now considers the owner for equals."

This reverts commit 93913b04c3.

The change caused build failures for Spring Data JDBC.

See #2972
Original pull request #2973
See spring-projects/spring-data-relational#1657
This commit is contained in:
Jens Schauder
2023-11-12 11:06:24 +01:00
parent a3f4ac6b51
commit 0c9f47703d
2 changed files with 18 additions and 26 deletions

View File

@@ -20,7 +20,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -41,7 +40,6 @@ import org.springframework.util.Assert;
* @author Oliver Gierke
* @author Christoph Strobl
* @author Mark Paluch
* @author Jens Schauder
*/
public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>> implements PersistentProperty<P> {
@@ -87,7 +85,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
this.association = Lazy.of(() -> isAssociation() ? createAssociation() : null);
this.owner = owner;
this.hashCode = Lazy.of(() -> Objects.hash(property, owner));
this.hashCode = Lazy.of(property::hashCode);
this.usePropertyAccess = Lazy.of(() -> owner.getType().isInterface() || CAUSE_FIELD.equals(getField()));
this.isAssociation = Lazy.of(() -> ASSOCIATION_TYPE != null && ASSOCIATION_TYPE.isAssignableFrom(rawType));
@@ -295,7 +293,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
return false;
}
return this.property.equals(that.property) && this.owner.equals(that.owner);
return this.property.equals(that.property);
}
@Override

View File

@@ -84,6 +84,16 @@ public class AbstractPersistentPropertyUnitTests {
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();
@@ -200,7 +210,7 @@ public class AbstractPersistentPropertyUnitTests {
@Test // DATACMNS-1139
void resolvesGenericsForRawType() {
var property = getProperty(Concrete.class, "genericField");
var property = getProperty(FirstConcrete.class, "genericField");
assertThat(property.getRawType()).isEqualTo(String.class);
}
@@ -233,15 +243,6 @@ public class AbstractPersistentPropertyUnitTests {
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 <T> BasicPersistentEntity<T, SamplePersistentProperty> getEntity(Class<T> type) {
return new BasicPersistentEntity<>(TypeInformation.of(type));
}
@@ -279,7 +280,11 @@ public class AbstractPersistentPropertyUnitTests {
}
class Concrete extends Generic<String> {
class FirstConcrete extends Generic<String> {
}
class SecondConcrete extends Generic<Integer> {
}
@@ -404,15 +409,4 @@ public class AbstractPersistentPropertyUnitTests {
class VavrWrapper {
io.vavr.collection.Map<String, String> vavrMap;
}
class Base {
Long id;
}
class Inherited1 extends Base {
}
class Inherited2 extends Base {
}
}