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 ?

        Attachments

          Activity

            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: