diff --git a/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java b/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java index 2063dc7aa2..3b13e11713 100644 --- a/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java +++ b/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java @@ -21,6 +21,7 @@ import java.io.Serializable; import java.lang.annotation.Annotation; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import org.springframework.core.annotation.AnnotatedElementUtils; @@ -38,6 +39,7 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ConcurrentReferenceHashMap; +import org.springframework.util.ConcurrentReferenceHashMap.ReferenceType; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -105,8 +107,9 @@ public BasicPersistentEntity(TypeInformation information, @Nullable Comparato this.associations = comparator == null ? new HashSet<>() : new TreeSet<>(new AssociationComparator<>(comparator)); this.propertyCache = new ConcurrentHashMap<>(); - this.annotationCache = new ConcurrentReferenceHashMap<>(); - this.propertyAnnotationCache = CollectionUtils.toMultiValueMap(new ConcurrentReferenceHashMap<>()); + this.annotationCache = new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK); + this.propertyAnnotationCache = CollectionUtils + .toMultiValueMap(new ConcurrentReferenceHashMap<>(16, ReferenceType.WEAK)); this.propertyAccessorFactory = BeanWrapperPropertyAccessorFactory.INSTANCE; this.typeAlias = Lazy.of(() -> getAliasFromAnnotation(getType())); this.isNewStrategy = Lazy.of(() -> Persistable.class.isAssignableFrom(information.getType()) // @@ -236,7 +239,7 @@ public void addPersistentProperty(P property) { } } - /* + /* * (non-Javadoc) * @see org.springframework.data.mapping.model.MutablePersistentEntity#setEvaluationContextProvider(org.springframework.data.spel.EvaluationContextProvider) */ @@ -469,7 +472,7 @@ public IdentifierAccessor getIdentifierAccessor(Object bean) { return hasIdProperty() ? new IdPropertyIdentifierAccessor(this, bean) : new AbsentIdentifierAccessor(bean); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mapping.PersistentEntity#isNew(java.lang.Object) */ @@ -481,7 +484,7 @@ public boolean isNew(Object bean) { return isNewStrategy.get().isNew(bean); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mapping.PersistentEntity#isImmutable() */ @@ -516,7 +519,7 @@ protected EvaluationContext getEvaluationContext(Object rootObject) { * Returns the default {@link IsNewStrategy} to be used. Will be a {@link PersistentEntityIsNewStrategy} by default. * Note, that this strategy only gets used if the entity doesn't implement {@link Persistable} as this indicates the * user wants to be in control over whether an entity is new or not. - * + * * @return * @since 2.1 */ @@ -526,7 +529,7 @@ protected IsNewStrategy getFallbackIsNewStrategy() { /** * Verifies the given bean type to no be {@literal null} and of the type of the current {@link PersistentEntity}. - * + * * @param bean must not be {@literal null}. */ private final void verifyBeanType(Object bean) {