diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java index 08e8d08fe..95ca4ffeb 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java @@ -1000,8 +1000,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, // Create query for entity with the id and old version MongoPersistentProperty idProperty = entity.getRequiredIdProperty(); - Object id = convertingAccessor.getProperty(idProperty) - .orElseThrow(() -> new IllegalStateException("Required id not found!")); + Object id = entity.getIdentifierAccessor(objectToSave).getRequiredIdentifier(); Query query = new Query(Criteria.where(idProperty.getName()).is(id).and(property.getName()).is(number)); UpdateResult result = doUpdate(collectionName, query, update, objectToSave.getClass(), false, false);