diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java index 2c25d186b..ee50e0da2 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryMethod.java @@ -128,8 +128,7 @@ public class MongoQueryMethod extends QueryMethod { MongoPersistentEntity collectionEntity = domainClass.isAssignableFrom(returnedObjectType) ? returnedEntity : managedEntity; - this.metadata = new SimpleMongoEntityMetadata((Class) returnedEntity.getType(), - collectionEntity.getCollection()); + this.metadata = new SimpleMongoEntityMetadata((Class) returnedEntity.getType(), collectionEntity); } return this.metadata; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/SimpleMongoEntityMetadata.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/SimpleMongoEntityMetadata.java index e248c604a..888802995 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/SimpleMongoEntityMetadata.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/SimpleMongoEntityMetadata.java @@ -15,6 +15,7 @@ */ package org.springframework.data.mongodb.repository.query; +import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity; import org.springframework.util.Assert; /** @@ -25,21 +26,22 @@ import org.springframework.util.Assert; class SimpleMongoEntityMetadata implements MongoEntityMetadata { private final Class type; - private final String collectionName; + private final MongoPersistentEntity collectionEntity; /** - * Creates a new {@link SimpleMongoEntityMetadata} using the given type and collection name. + * Creates a new {@link SimpleMongoEntityMetadata} using the given type and {@link MongoPersistentEntity} to use for + * collection lookups. * * @param type must not be {@literal null}. - * @param collectionName must not be {@literal null} or empty. + * @param collectionEntity must not be {@literal null} or empty. */ - public SimpleMongoEntityMetadata(Class type, String collectionName) { + public SimpleMongoEntityMetadata(Class type, MongoPersistentEntity collectionEntity) { Assert.notNull(type, "Type must not be null!"); - Assert.hasText(collectionName, "Collection name must not be null or empty!"); + Assert.notNull(collectionEntity, "Collection entity must not be null or empty!"); this.type = type; - this.collectionName = collectionName; + this.collectionEntity = collectionEntity; } /* @@ -55,6 +57,6 @@ class SimpleMongoEntityMetadata implements MongoEntityMetadata { * @see org.springframework.data.mongodb.repository.query.MongoEntityMetadata#getCollectionName() */ public String getCollectionName() { - return collectionName; + return collectionEntity.getCollection(); } }