@ -914,9 +914,7 @@ public class QueryMapper {
@@ -914,9 +914,7 @@ public class QueryMapper {
MongoPersistentProperty idProperty = entity . getIdProperty ( ) ;
if ( idProperty ! = null ) {
return name . equals ( idProperty . getName ( ) ) | | name . equals ( idProperty . getFieldName ( ) )
| | name . endsWith ( "." + idProperty . getName ( ) ) | | name . endsWith ( "." + idProperty . getFieldName ( ) ) ;
return name . equals ( idProperty . getName ( ) ) | | name . equals ( idProperty . getFieldName ( ) ) ;
}
return DEFAULT_ID_NAMES . contains ( name ) ;
@ -1004,13 +1002,14 @@ public class QueryMapper {
@@ -1004,13 +1002,14 @@ public class QueryMapper {
@Nullable
private PersistentPropertyPath < MongoPersistentProperty > getPath ( String pathExpression ) {
try {
String rawPath = pathExpression . replaceAll ( "\\.\\d+" , "" ) ;
PropertyPath path = PropertyPath . from ( pathExpression . replaceAll ( "\\.\\d+" , "" ) , entity . getTypeInformation ( ) ) ;
PropertyPath path = forName ( rawPath ) ;
if ( path = = null | | isPathToJavaLangClassProperty ( path ) ) {
return null ;
}
if ( isPathToJavaLangClassProperty ( path ) ) {
return null ;
}
try {
PersistentPropertyPath < MongoPersistentProperty > propertyPath = mappingContext . getPersistentPropertyPath ( path ) ;
@ -1032,7 +1031,30 @@ public class QueryMapper {
@@ -1032,7 +1031,30 @@ public class QueryMapper {
}
return propertyPath ;
} catch ( InvalidPersistentPropertyPath e ) {
return null ;
}
}
/ * *
* Querydsl happens to map id fields directly to { @literal _id } which breaks { @link PropertyPath } resolution . So if
* the first attempt fails we try to replace { @literal _id } with just { @literal id } and see if we can resolve if
* then .
*
* @param path
* @return the path or { @literal null }
* /
@Nullable
private PropertyPath forName ( String path ) {
try {
return PropertyPath . from ( path , entity . getTypeInformation ( ) ) ;
} catch ( PropertyReferenceException | InvalidPersistentPropertyPath e ) {
if ( path . endsWith ( "_id" ) ) {
return forName ( path . substring ( 0 , path . length ( ) - 3 ) + "id" ) ;
}
return null ;
}
}