Example usage for org.springframework.data.mongodb.core.mapping MongoPersistentProperty getName

List of usage examples for org.springframework.data.mongodb.core.mapping MongoPersistentProperty getName

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.mapping MongoPersistentProperty getName.

Prototype

String getName();

Source Link

Document

The name of the property

Usage

From source file:com.sangupta.jerry.mongodb.MongoTemplateBasicOperations.java

/**
 * Get the basic services from mongo template
 *///  www .j a  va 2  s .  c o m
private synchronized void fetchMappingContextAndConversionService() {
    if (mappingContext == null) {
        MongoConverter mongoConverter = this.mongoTemplate.getConverter();
        mappingContext = mongoConverter.getMappingContext();
        conversionService = mongoConverter.getConversionService();

        MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityClass);
        MongoPersistentProperty idProperty = persistentEntity.getIdProperty();
        this.idKey = idProperty == null ? "_id" : idProperty.getName();
    }
}

From source file:org.springframework.data.mongodb.core.MongoTemplate.java

public <T> T findById(Object id, Class<T> entityClass, String collectionName) {
    MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityClass);
    MongoPersistentProperty idProperty = persistentEntity.getIdProperty();
    String idKey = idProperty == null ? ID : idProperty.getName();
    return doFindOne(collectionName, new BasicDBObject(idKey, id), null, entityClass);
}