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 e790d8e0a..3a8589fcc 100644 --- a/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java +++ b/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java @@ -131,7 +131,8 @@ public class BasicPersistentEntity> implement this.typeAlias = Lazy.of(() -> getAliasFromAnnotation(getType())); this.isNewStrategy = Lazy.of(() -> Persistable.class.isAssignableFrom(information.getType()) // ? PersistableIsNewStrategy.INSTANCE - : PersistentEntityIsNewStrategy.of(this)); + : getFallbackIsNewStrategy()); + this.isImmutable = Lazy.of(() -> isAnnotationPresent(Immutable.class)); } @@ -520,6 +521,18 @@ public class BasicPersistentEntity> implement return evaluationContextProvider.getEvaluationContext(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 + */ + protected IsNewStrategy getFallbackIsNewStrategy() { + return PersistentEntityIsNewStrategy.of(this); + } + /** * Verifies the given bean type to no be {@literal null} and of the type of the current {@link PersistentEntity}. *