Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Aug 6, 2015 · 1 comment
Assignees
Labels
in: core Issues in core support in: mapping Mapping and conversion infrastructure type: bug A general bug

Comments

@spring-projects-issues
Copy link

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

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

Please refrain from cross-posting. I saw and replied to your post on StackOverflow

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core support in: mapping Mapping and conversion infrastructure labels Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support in: mapping Mapping and conversion infrastructure type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants