Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-320

Mapping ambiguation detection is too aggressive

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.5.1
    • Fix Version/s: 1.6 M1, 1.5.2
    • Component/s: Mapping / Conversion
    • Labels:
      None
    • Environment:
      Spring 3.2.2.RELEASE

      Description

      We're using both Jackson 1.9.x annotations and Spring Data annotations on the same entity, since we have a REST/JSON api and persist to Mongo.

      Here's the Code:

      @Id
      private String id;
      
      @Override
      @JsonProperty("_id")
      public String getId() {
       return id;
      }
      
      @JsonProperty("_id")
      public void setId(String id) {
        this.id = id;
      }
      

      At some point, we had to add both annotations to make it crystal clear for Jackson that it should both serialize and deserialize _i to the getter/setter. This worked with Spring Data Mongo 1.1.

      After upgrading to Spring Data Mongo 1.2.1, we get this exception:

      org.springframework.data.mapping.model.MappingException: Ambiguous mapping! Annotation interface org.codehaus.jackson.annotate.JsonProperty configured multiple times on accessor methods of property id in class com.xxxx.xxxxx.xxxxx.Foo!
      	at org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.populateAnnotationCache(AnnotationBasedPersistentProperty.java:86) ~[spring-data-commons-1.5.1.RELEASE.jar:na]
      	at org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.<init>(AnnotationBasedPersistentProperty.java:62) ~[spring-data-commons-1.5.1.RELEASE.jar:na]
      	at org.springframework.data.mongodb.core.mapping.BasicMongoPersistentProperty.<init>(BasicMongoPersistentProperty.java:73) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      	at org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty.<init>(CachingMongoPersistentProperty.java:44) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      	at org.springframework.data.mongodb.core.mapping.MongoMappingContext.createPersistentProperty(MongoMappingContext.java:65) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      	at org.springframework.data.mongodb.core.mapping.MongoMappingContext.createPersistentProperty(MongoMappingContext.java:37) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:391) ~[spring-data-commons-1.5.1.RELEASE.jar:na]
      	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:570) ~[spring-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]
      	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:283) ~[spring-data-commons-1.5.1.RELEASE.jar:na]
      	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:190) ~[spring-data-commons-1.5.1.RELEASE.jar:na]
      	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:159) ~[spring-data-commons-1.5.1.RELEASE.jar:na]
      	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:69) ~[spring-data-commons-1.5.1.RELEASE.jar:na]
      	at org.springframework.data.mongodb.core.MongoTemplate.determineCollectionName(MongoTemplate.java:1607) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      	at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1058) ~[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      

        Attachments

          Activity

            People

            • Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              askogman Adam Skogman
              Last updater:
              Trevor Marshall
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: