diff --git a/src/main/java/org/springframework/data/mapping/PropertyPath.java b/src/main/java/org/springframework/data/mapping/PropertyPath.java index ee99106b8..45458fa4e 100644 --- a/src/main/java/org/springframework/data/mapping/PropertyPath.java +++ b/src/main/java/org/springframework/data/mapping/PropertyPath.java @@ -19,6 +19,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Value; +import java.beans.Introspector; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -86,7 +87,7 @@ public class PropertyPath implements Streamable { Assert.notNull(owningType, "Owning type must not be null!"); Assert.notNull(base, "Perviously found properties must not be null!"); - String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name); + String propertyName = Introspector.decapitalize(name); TypeInformation propertyType = owningType.getProperty(propertyName); if (propertyType == null) { diff --git a/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java b/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java index a04cb6063..d4e5c8971 100755 --- a/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/PropertyPathUnitTests.java @@ -386,6 +386,21 @@ public class PropertyPathUnitTests { .isThrownBy(() -> PropertyPath.from(path, Left.class)); } + @Test // DATACMNS-1304 + public void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() { + assertThat(from("categoryB", Product.class).toDotPath()).isEqualTo("categoryB"); + } + + @Test // DATACMNS-1304 + public void resolvesPropertyPathWithUppercaseLettersPropertyEnding() { + assertThat(from("categoryABId", Product.class).toDotPath()).isEqualTo("categoryAB.id"); + } + + @Test // DATACMNS-1304 + public void detectsNestedSingleCharacterProperty() { + assertThat(from("category_B", Product.class).toDotPath()).isEqualTo("category.b"); + } + private class Foo { String userName; @@ -430,4 +445,18 @@ public class PropertyPathUnitTests { private class Right { Left bar; } + + // DATACMNS-1304 + private class Product { + Category category; + Category categoryB; + Category categoryAB; + } + + private class Category { + B b; + String id; + } + + private class B {} } diff --git a/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java b/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java index 2905f2b46..1b157e670 100755 --- a/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java +++ b/src/test/java/org/springframework/data/repository/query/parser/PartTreeUnitTests.java @@ -601,16 +601,6 @@ public class PartTreeUnitTests { assertThat(tree.hasPredicate()).isFalse(); } - @Test // DATACMNS-1304 - public void resolvesPropertyPathWithSingleUppercaseLetterPropertyEnding() { - assertThat(new PartTree("findByCategoryBId", Product.class)).isNotNull(); - } - - @Test // DATACMNS-1304 - public void resolvesPropertyPathWithUppercaseLettersPropertyEnding() { - assertThat(new PartTree("findByCategoryABId", Product.class)).isNotNull(); - } - private static void assertLimiting(String methodName, Class entityType, boolean limiting, Integer maxResults) { assertLimiting(methodName, entityType, limiting, maxResults, false); } @@ -734,10 +724,6 @@ public class PartTreeUnitTests { Anders getAnders(); // constains And keyword Category getCategory(); - - Category getCategoryB(); // contains single uppercase letter at the end - - Category getCategoryAB(); // contains uppercase letters at the end } interface Category {