|
20 | 20 | import java.util.HashMap;
|
21 | 21 | import java.util.List;
|
22 | 22 | import java.util.Map;
|
| 23 | +import java.util.regex.Pattern; |
23 | 24 |
|
24 | 25 | import org.springframework.data.domain.Sort;
|
| 26 | +import org.springframework.data.mapping.MappingException; |
25 | 27 | import org.springframework.data.mapping.PersistentPropertyPath;
|
26 | 28 | import org.springframework.data.mapping.PropertyPath;
|
27 | 29 | import org.springframework.data.mapping.PropertyReferenceException;
|
28 |
| -import org.springframework.data.mapping.context.InvalidPersistentPropertyPath; |
29 | 30 | import org.springframework.data.mapping.context.MappingContext;
|
30 | 31 | import org.springframework.data.r2dbc.convert.R2dbcConverter;
|
31 | 32 | import org.springframework.data.r2dbc.dialect.BindMarker;
|
@@ -626,7 +627,7 @@ protected static class MetadataBackedField extends Field {
|
626 | 627 |
|
627 | 628 | private final RelationalPersistentEntity<?> entity;
|
628 | 629 | private final MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext;
|
629 |
| - private final RelationalPersistentProperty property; |
| 630 | + private final @Nullable RelationalPersistentProperty property; |
630 | 631 | private final @Nullable PersistentPropertyPath<RelationalPersistentProperty> path;
|
631 | 632 |
|
632 | 633 | /**
|
@@ -675,26 +676,35 @@ public SqlIdentifier getMappedColumnName() {
|
675 | 676 | /**
|
676 | 677 | * Returns the {@link PersistentPropertyPath} for the given {@code pathExpression}.
|
677 | 678 | *
|
678 |
| - * @param pathExpression |
| 679 | + * @param pathExpression the path expression to use. |
679 | 680 | * @return
|
680 | 681 | */
|
681 | 682 | @Nullable
|
682 | 683 | private PersistentPropertyPath<RelationalPersistentProperty> getPath(String pathExpression) {
|
683 | 684 |
|
684 | 685 | try {
|
685 | 686 |
|
686 |
| - PropertyPath path = PropertyPath.from(pathExpression, this.entity.getTypeInformation()); |
| 687 | + PropertyPath path = forName(pathExpression); |
687 | 688 |
|
688 | 689 | if (isPathToJavaLangClassProperty(path)) {
|
689 | 690 | return null;
|
690 | 691 | }
|
691 | 692 |
|
692 | 693 | return this.mappingContext.getPersistentPropertyPath(path);
|
693 |
| - } catch (PropertyReferenceException | InvalidPersistentPropertyPath e) { |
| 694 | + } catch (MappingException | PropertyReferenceException e) { |
694 | 695 | return null;
|
695 | 696 | }
|
696 | 697 | }
|
697 | 698 |
|
| 699 | + private PropertyPath forName(String path) { |
| 700 | + |
| 701 | + if (entity.getPersistentProperty(path) != null) { |
| 702 | + return PropertyPath.from(Pattern.quote(path), entity.getTypeInformation()); |
| 703 | + } |
| 704 | + |
| 705 | + return PropertyPath.from(path, entity.getTypeInformation()); |
| 706 | + } |
| 707 | + |
698 | 708 | private boolean isPathToJavaLangClassProperty(PropertyPath path) {
|
699 | 709 | return path.getType().equals(Class.class) && path.getLeafProperty().getOwningType().getType().equals(Class.class);
|
700 | 710 | }
|
|
0 commit comments