Use newly introduced findOne(…) of MongoOperations inside SimpleMongoRepository.findById(…).
This commit is contained in:
@@ -106,13 +106,10 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends
|
|||||||
public T findById(ID id) {
|
public T findById(ID id) {
|
||||||
|
|
||||||
MongoConverter converter = template.getConverter();
|
MongoConverter converter = template.getConverter();
|
||||||
|
|
||||||
ObjectId objectId = converter.convertObjectId(id);
|
ObjectId objectId = converter.convertObjectId(id);
|
||||||
|
|
||||||
List<T> result =
|
return template.findOne(getCollectionName(getDomainClass()), new Query(
|
||||||
template.find(getCollectionName(getDomainClass()), new Query(
|
where("_id").is(objectId)), getDomainClass());
|
||||||
where("_id").is(objectId)), getDomainClass());
|
|
||||||
return result.isEmpty() ? null : result.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user