spring-data-mongodb在@DBRef字段上的Query.fields()。slice()抛出MappingException

时间:2015-08-06 13:16:26

标签: spring spring-data-mongodb

我在模型中对某些@DBRef字段进行切片访问时出现问题。我使用spring-data-mongodb-1.8.0.M1.jar

该模型如下:

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

我需要切片访问成员变量。

我使用此查询:

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);

但我得到了这个例外:

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)

其中一个字段

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

已设定。它检查isExists,但不会对像isSliced(它还不存在)这样的东西进行检查,因此被评估为true,并且作为原因,尝试转换不存在的关联,在这种情况下,只是slice-directive (整数数组)。当我在调试时将变量needsAssociationConversion设置为false时,好像有一种keyword.isSlice()检查完成后,一切正常。

  

这是一个错误吗?

可执行项目在这里

https://github.com/zhsyourai/sliceDemo

0 个答案:

没有答案