diff --git a/src/main/java/org/springframework/data/mapping/PreferredConstructor.java b/src/main/java/org/springframework/data/mapping/PreferredConstructor.java index 5cbd4e3c0..a779c6a2a 100644 --- a/src/main/java/org/springframework/data/mapping/PreferredConstructor.java +++ b/src/main/java/org/springframework/data/mapping/PreferredConstructor.java @@ -115,6 +115,10 @@ public class PreferredConstructor> { /** * Returns whether the given {@link PersistentProperty} is referenced in a constructor argument of the * {@link PersistentEntity} backing this {@link PreferredConstructor}. + *

+ * Results of this call are cached and reused on the next invocation. Calling this method for a + * {@link PersistentProperty} that was not yet added to its owning {@link PersistentEntity} will capture that state + * and return the same result after adding {@link PersistentProperty} to its entity. * * @param property must not be {@literal null}. * @return {@literal true} if the {@link PersistentProperty} is used in the constructor. @@ -132,12 +136,13 @@ public class PreferredConstructor> { boolean result = false; for (Parameter parameter : parameters) { if (parameter.maps(property)) { - isPropertyParameterCache.put(property, true); result = true; break; } } + isPropertyParameterCache.put(property, result); + return result; }