Browse Source

Use newly introduced findOne(…) of MongoOperations inside SimpleMongoRepository.findById(…).

pull/1/head
Oliver Gierke 15 years ago
parent
commit
bb8a4d93c6
  1. 7
      spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoRepository.java

7
spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/repository/SimpleMongoRepository.java

@ -106,13 +106,10 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends @@ -106,13 +106,10 @@ public class SimpleMongoRepository<T, ID extends Serializable> extends
public T findById(ID id) {
MongoConverter converter = template.getConverter();
ObjectId objectId = converter.convertObjectId(id);
List<T> result =
template.find(getCollectionName(getDomainClass()), new Query(
where("_id").is(objectId)), getDomainClass());
return result.isEmpty() ? null : result.get(0);
return template.findOne(getCollectionName(getDomainClass()), new Query(
where("_id").is(objectId)), getDomainClass());
}

Loading…
Cancel
Save