@@ -373,7 +373,9 @@ protected Document getMappedKeyword(Keyword keyword, @Nullable MongoPersistentEn
373373 if (keyword .isOrOrNor () || (keyword .hasIterableValue () && !keyword .isGeometry ())) {
374374
375375 Iterable <?> conditions = keyword .getValue ();
376- List <Object > newConditions = conditions instanceof Collection ? new ArrayList <>(((Collection <?>) conditions ).size ()) : new ArrayList <>();
376+ List <Object > newConditions = conditions instanceof Collection
377+ ? new ArrayList <>(((Collection <?>) conditions ).size ())
378+ : new ArrayList <>();
377379
378380 for (Object condition : conditions ) {
379381 newConditions .add (isDocument (condition ) ? getMappedObject ((Document ) condition , entity )
@@ -431,8 +433,10 @@ protected Object getMappedValue(Field documentField, Object sourceValue) {
431433
432434 Object value = applyFieldTargetTypeHintToValue (documentField , sourceValue );
433435
434- if (documentField .getProperty () != null && converter .getCustomConversions ().hasValueConverter (documentField .getProperty ())) {
435- return converter .getCustomConversions ().getPropertyValueConversions ().getValueConverter (documentField .getProperty ())
436+ if (documentField .getProperty () != null
437+ && converter .getCustomConversions ().hasValueConverter (documentField .getProperty ())) {
438+ return converter .getCustomConversions ().getPropertyValueConversions ()
439+ .getValueConverter (documentField .getProperty ())
436440 .write (value , new MongoConversionContext (documentField .getProperty (), converter ));
437441 }
438442
@@ -616,7 +620,11 @@ protected Object delegateConvertToMongoType(Object source, @Nullable MongoPersis
616620 }
617621
618622 protected Object convertAssociation (Object source , Field field ) {
619- return convertAssociation (source , field .getProperty ());
623+ Object value = convertAssociation (source , field .getProperty ());
624+ if (value != null && field .isIdField () && field .getFieldType () != value .getClass ()) {
625+ return convertId (value , field .getFieldType ());
626+ }
627+ return value ;
620628 }
621629
622630 /**
@@ -1042,6 +1050,9 @@ public TypeInformation<?> getTypeHint() {
10421050 return TypeInformation .OBJECT ;
10431051 }
10441052
1053+ public Class <?> getFieldType () {
1054+ return Object .class ;
1055+ }
10451056 }
10461057
10471058 /**
@@ -1170,6 +1181,11 @@ private Association<MongoPersistentProperty> findAssociation() {
11701181 return null ;
11711182 }
11721183
1184+ @ Override
1185+ public Class <?> getFieldType () {
1186+ return property .getFieldType ();
1187+ }
1188+
11731189 @ Override
11741190 public String getMappedKey () {
11751191 return path == null ? name : path .toDotPath (isAssociation () ? getAssociationConverter () : getPropertyConverter ());
0 commit comments