Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-761

ClassCastException in SpringDataMongodbSerializer.getKeyForPath

    Details

    • Sprint:
      The Road to Codd M1

      Description

      Hello,

      I recently upgraded from querydsl 2.9.0 to 3.2.3 and spring-data-mongodb 1.2.1.RELEASE to 1.3.1.RELEASE.

      Currently, some of my MongoDB entities have inner objects stored using maps with Long keys :

          @Document(collection = "xxx")
          @QueryEntity
          public class ObjectA {
              private Map<Long, ObjectB> objects;
          }

      I used to query such objects using the QueryDslPredicateExecutor repository interface. For instance, I used to check whether a map key was present with : QObjectA.objectA.objects.get(objectId).isNotNull()

      With the updated versions, I now get a ClassCastException I didn't experience before :

          java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
              at com.mysema.query.types.PathMetadata.getName(PathMetadata.java:70)
              at org.springframework.data.mongodb.repository.support.SpringDataMongodbSerializer.getKeyForPath(SpringDataMongodbSerializer.java:66)

      Judging by the source code of PathMetadata, it looks like the correct behaviour might be to use getElement().toString() instead of getName() :
      https://github.com/mysema/querydsl/blob/master/querydsl-core/src/main/java/com/mysema/query/types/PathMetadata.java

      What do you think ?

        Activity

        Hide
        olivergierke Oliver Gierke added a comment -

        Thanks for the report! There either seems to be a bug in Querydsl or a misunderstanding on our side of how to obtain the path segment name to be used when marshaling the objects. I just got in touch with the Querydsl guys for further insight and will report back as soon as I here some news.

        Show
        olivergierke Oliver Gierke added a comment - Thanks for the report! There either seems to be a bug in Querydsl or a misunderstanding on our side of how to obtain the path segment name to be used when marshaling the objects. I just got in touch with the Querydsl guys for further insight and will report back as soon as I here some news.
        Hide
        adupuis Antoine Dupuis added a comment -

        Actually, I already discussed this issue with Timowest. He seemed to believe this was more a spring-data issue than a query-dsl one, which is why I filled a report here.
        https://github.com/mysema/querydsl/issues/512

        Show
        adupuis Antoine Dupuis added a comment - Actually, I already discussed this issue with Timowest. He seemed to believe this was more a spring-data issue than a query-dsl one, which is why I filled a report here. https://github.com/mysema/querydsl/issues/512

          People

          • Assignee:
            olivergierke Oliver Gierke
            Reporter:
            adupuis Antoine Dupuis
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Agile