-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed as not planned
Closed as not planned
Copy link
Labels
in: mappingMapping and conversion infrastructureMapping and conversion infrastructuretype: bugA general bugA general bug
Description
Jose Luis opened DATAMONGO-1426 and commented
Hi
In MongoTemplate findById it uses the POJO property name to build the query instead of the field name in the database.
public <T> T findById(Object id, Class<T> entityClass, String collectionName) {
MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityClass);
MongoPersistentProperty idProperty = persistentEntity == null ? null : persistentEntity.getIdProperty();
String idKey = idProperty == null ? ID_FIELD : idProperty.getName();
return doFindOne(collectionName, new BasicDBObject(idKey, id), null, entityClass);
}
if the @Id
is pressent, then the query issues the field name in the POJO instead in the db side, for instance, if we'd have this class:
public class Customer
{
@Id
String customerId;
}
then the query of findOne would be { customerId : "12345" } instead of { _id : "12345"}
save is working correctly, and uses the _id field. Actually removing the @Id
, makes it work correctly. (String idKey = idProperty == null ? ID_FIELD : idProperty.getName();).
so actually using idProperty.getFieldName() should fix it.
Also exists fail, a object recently created does not exists.
Affects: 1.9.1 (Hopper SR1)
0 votes, 5 watchers
Metadata
Metadata
Assignees
Labels
in: mappingMapping and conversion infrastructureMapping and conversion infrastructuretype: bugA general bugA general bug