Skip to content

$slice access to @DBRef field throw exception [DATAMONGO-1272] #2191

Closed
@spring-projects-issues

Description

@spring-projects-issues

Zhu Hongshang opened DATAMONGO-1272 and commented

There is a model is like:

class Model {
....
@DBRef
List<OtherModel> members;
...
}

and I need sliced access to the members variable.

I use this query:

ObjectId objectId = new ObjectId("55c36f44f359d8a455a21f68");
Query query = new Query(Criteria.where("_id").is(objectId));
query.fields().slice("members", pageable.getOffset(), pageable.getPageSize());
List<Model> models = mongoTemplate.findOne(query, Model.class);

And I get this exception:

org.springframework.data.mapping.model.MappingException: No id property found on class class [Ljava.lang.Integer;
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:842)
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:329)
    at org.springframework.data.mongodb.core.convert.QueryMapper.createDbRefFor(QueryMapper.java:460)
    at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:417)
    at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:378)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:257)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObjectForField(QueryMapper.java:200)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:123)
    at org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:1647)
    at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:563)
    at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:558)

where a field:

boolean needsAssociationConversion = property.isAssociation() && !keyword.isExists();

is set. It checks against isExists, but not against something like isSliced (which does not yet exist) and therefore is evaluated to true and, as a cause, tries to convert the non-existing association which is, in this case, just the slice-directive (an integer array). When I set the variable needsAssociationConversion to false while debugging, as if a kind of

keyword.isSlice() 

check was done, everything works fine


Affects: 1.8 M1 (Gosling)

Reference URL: http://stackoverflow.com/questions/31856871/spring-data-mongodb-query-fields-slice-on-dbref-field-throws-mappingexcepti

Metadata

Metadata

Labels

in: coreIssues in core supportin: mappingMapping and conversion infrastructuretype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions