Announcement Announcement Module
Collapse
No announcement yet.
MongoDB: $slice on embedded data throws MappingException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongoDB: $slice on embedded data throws MappingException

    I have a problem with sliced access to some embedded data in my model.
    I use spring-data-mongodb-1.5.0.RELEASE.jar

    The model is like

    Code:
    class A {
    ...
    @DBRef(lazy=false)
    List<A> members;
    ...
    }
    and I need paged/sliced access to the embedded members variable.

    I use this query

    Code:
    ObjectId objectId = new ObjectId("538f1403e4b0121de0831bd7");
    Query query = new Query(Criteria.where("_id").is(objectId));
    query.fields().slice("members", pageable.getOffset(), pageable.getPageSize());
    List<A> members = this.operations.find(query, A.class);
    The query shows itself (toString()) as
    Code:
    Query: { "_id" : { "$oid" : "538f1403e4b0121de0831bd7"}}, Fields: { "members" : { "$slice" : [ 0 , 10]}}, Sort: null
    which looks valid from my point of view. Still, I get a
    Code:
    org.springframework.data.mapping.model.MappingException: No id property found on class class [Ljava.lang.Integer;
    at org.springframework.data.mongodb.core.convert.Mapp ingMongoConverter.createDBRef(MappingMongoConverte r.java:774)
    at org.springframework.data.mongodb.core.convert.Mapp ingMongoConverter.toDBRef(MappingMongoConverter.ja va:302)
    at org.springframework.data.mongodb.core.convert.Quer yMapper.createDbRefFor(QueryMapper.java:389)
    at org.springframework.data.mongodb.core.convert.Quer yMapper.convertAssociation(QueryMapper.java:346)
    at org.springframework.data.mongodb.core.convert.Quer yMapper.convertAssociation(QueryMapper.java:313)
    at org.springframework.data.mongodb.core.convert.Quer yMapper.getMappedKeyword(QueryMapper.java:193)
    at org.springframework.data.mongodb.core.convert.Quer yMapper.getMappedObjectForField(QueryMapper.java:1 36)
    at org.springframework.data.mongodb.core.convert.Quer yMapper.getMappedObject(QueryMapper.java:114)
    at org.springframework.data.mongodb.core.MongoTemplat e.doFind(MongoTemplate.java:1599)
    at org.springframework.data.mongodb.core.MongoTemplat e.doFind(MongoTemplate.java:1591)
    at org.springframework.data.mongodb.core.MongoTemplat e.find(MongoTemplate.java:535)
    at org.springframework.data.mongodb.core.MongoTemplat e.find(MongoTemplate.java:526)
    I think the query building should not run at all into createDBRef here, as it is a sliced query which does not required DBRefs at all.
    The problem might be in class
    Code:
    org.springframework.data.mongodb.core.convert.QueryMapper
    in method
    Code:
    protected DBObject getMappedKeyword(Field property, Keyword keyword)
    where a field
    Code:
    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 isSlice-check was done, everything works fine.

    Is there another way to build my query or is this a bug?

  • #2
    Please, move your question to the StackOverflow - we are going to close this forum soon and rely on SO.
    We need to clean this forum (old unanswered question) before close it.

    Thanks for understanding

    Comment

    Working...
    X