diff --git a/pom.xml b/pom.xml
index d9ee91c910..c5032a084e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.data
spring-data-relational-parent
- 3.2.0-SNAPSHOT
+ 3.2.0-1657-aggregate-path-SNAPSHOT
pom
Spring Data Relational Parent
diff --git a/spring-data-jdbc-distribution/pom.xml b/spring-data-jdbc-distribution/pom.xml
index 271486f02a..b5ea1d4fa3 100644
--- a/spring-data-jdbc-distribution/pom.xml
+++ b/spring-data-jdbc-distribution/pom.xml
@@ -14,7 +14,7 @@
org.springframework.data
spring-data-relational-parent
- 3.2.0-SNAPSHOT
+ 3.2.0-1657-aggregate-path-SNAPSHOT
../pom.xml
diff --git a/spring-data-jdbc/pom.xml b/spring-data-jdbc/pom.xml
index 2ac75e7993..91b9f04aca 100644
--- a/spring-data-jdbc/pom.xml
+++ b/spring-data-jdbc/pom.xml
@@ -6,7 +6,7 @@
4.0.0
spring-data-jdbc
- 3.2.0-SNAPSHOT
+ 3.2.0-1657-aggregate-path-SNAPSHOT
Spring Data JDBC
Spring Data module for JDBC repositories.
@@ -15,7 +15,7 @@
org.springframework.data
spring-data-relational-parent
- 3.2.0-SNAPSHOT
+ 3.2.0-1657-aggregate-path-SNAPSHOT
diff --git a/spring-data-r2dbc/pom.xml b/spring-data-r2dbc/pom.xml
index d65f06a082..490853b958 100644
--- a/spring-data-r2dbc/pom.xml
+++ b/spring-data-r2dbc/pom.xml
@@ -6,7 +6,7 @@
4.0.0
spring-data-r2dbc
- 3.2.0-SNAPSHOT
+ 3.2.0-1657-aggregate-path-SNAPSHOT
Spring Data R2DBC
Spring Data module for R2DBC
@@ -15,7 +15,7 @@
org.springframework.data
spring-data-relational-parent
- 3.2.0-SNAPSHOT
+ 3.2.0-1657-aggregate-path-SNAPSHOT
diff --git a/spring-data-relational/pom.xml b/spring-data-relational/pom.xml
index 74f350faa8..656d648d06 100644
--- a/spring-data-relational/pom.xml
+++ b/spring-data-relational/pom.xml
@@ -6,7 +6,7 @@
4.0.0
spring-data-relational
- 3.2.0-SNAPSHOT
+ 3.2.0-1657-aggregate-path-SNAPSHOT
Spring Data Relational
Spring Data Relational support
@@ -14,7 +14,7 @@
org.springframework.data
spring-data-relational-parent
- 3.2.0-SNAPSHOT
+ 3.2.0-1657-aggregate-path-SNAPSHOT
diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DefaultAggregatePath.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DefaultAggregatePath.java
index 015857e985..0c3975626a 100644
--- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DefaultAggregatePath.java
+++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DefaultAggregatePath.java
@@ -52,7 +52,7 @@ class DefaultAggregatePath implements AggregatePath {
this.context = context;
this.path = (PersistentPropertyPath) path;
- this.rootType = null;
+ this.rootType = path.getBaseProperty().getOwner();
}
DefaultAggregatePath(RelationalMappingContext context, RelationalPersistentEntity> rootType) {
diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java
index ac453b4a55..10c66cdc8c 100644
--- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java
+++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java
@@ -186,11 +186,13 @@ protected void applyDefaults(BasicRelationalPersistentProperty persistentPropert
*/
public AggregatePath getAggregatePath(PersistentPropertyPath extends RelationalPersistentProperty> path) {
- AggregatePath aggregatePath = aggregatePathCache.get(path);
+ AggregatePathCacheKey cacheKey = AggregatePathCacheKey.of(path);
+
+ AggregatePath aggregatePath = aggregatePathCache.get(cacheKey);
if (aggregatePath == null) {
aggregatePath = new DefaultAggregatePath(this, path);
- aggregatePathCache.put(path, aggregatePath);
+ aggregatePathCache.put(cacheKey, aggregatePath);
}
return aggregatePath;
@@ -198,13 +200,26 @@ public AggregatePath getAggregatePath(PersistentPropertyPath extends Relationa
public AggregatePath getAggregatePath(RelationalPersistentEntity> type) {
- AggregatePath aggregatePath = aggregatePathCache.get(type);
+ AggregatePathCacheKey cacheKey = AggregatePathCacheKey.of(type);
+
+ AggregatePath aggregatePath = aggregatePathCache.get(cacheKey);
if (aggregatePath == null) {
aggregatePath = new DefaultAggregatePath(this, type);
- aggregatePathCache.put(type, aggregatePath);
+ aggregatePathCache.put(cacheKey, aggregatePath);
}
return aggregatePath;
}
+
+ private record AggregatePathCacheKey(RelationalPersistentEntity> root,@Nullable PersistentPropertyPath extends RelationalPersistentProperty> path) {
+ static AggregatePathCacheKey of(RelationalPersistentEntity> root) {
+ return new AggregatePathCacheKey(root, null);
+ }
+ static AggregatePathCacheKey of(PersistentPropertyPath extends RelationalPersistentProperty> path) {
+
+ RelationalPersistentEntity> root = path.getBaseProperty().getOwner();
+ return new AggregatePathCacheKey(root, path);
+ }
+ }
}
diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/RelationalMappingContextUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/RelationalMappingContextUnitTests.java
index c0377fdca7..ee7e3ce24c 100644
--- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/RelationalMappingContextUnitTests.java
+++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/RelationalMappingContextUnitTests.java
@@ -104,6 +104,20 @@ void correctlyCascadesPrefix() {
assertThat(name.getColumnName()).isEqualTo(SqlIdentifier.quoted("PRNT_CHLD_NAME"));
}
+ @Test // GH-1657
+ void aggregatePathsOfBasePropertyForDifferentInheritedEntitiesAreDifferent() {
+
+ PersistentPropertyPath path1 = context.getPersistentPropertyPath("name",
+ Inherit1.class);
+ PersistentPropertyPath path2 = context.getPersistentPropertyPath("name",
+ Inherit2.class);
+
+ AggregatePath aggregatePath1 = context.getAggregatePath(path1);
+ AggregatePath aggregatePath2 = context.getAggregatePath(path2);
+
+ assertThat(aggregatePath1).isNotEqualTo(aggregatePath2);
+ }
+
static class EntityWithUuid {
@Id UUID uuid;
}
@@ -121,4 +135,12 @@ static class Child {
String name;
}
+ static class Base {
+ String name;
+ }
+
+ static class Inherit1 extends Base {}
+
+ static class Inherit2 extends Base {}
+
}