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!

Spring JIRA | Adam Skogman | 4 years ago
tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    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: {code:java} @Id private String id; @Override @JsonProperty("_id") public String getId() { return id; } @JsonProperty("_id") public void setId(String id) { this.id = id; } {code} 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: {noformat} 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] {noformat}

    Spring JIRA | 4 years ago | Adam Skogman
    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!
  2. 0

    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: {code:java} @Id private String id; @Override @JsonProperty("_id") public String getId() { return id; } @JsonProperty("_id") public void setId(String id) { this.id = id; } {code} 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: {noformat} 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] {noformat}

    Spring JIRA | 4 years ago | Adam Skogman
    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!
  3. 0

    [HHH-9114] @IdClass with @MappedSuperclass results in "property not found" - Hibernate JIRA

    atlassian.net | 1 year ago
    org.springframework.data.mapping.model.MappingException: Ambiguous mapping! Annotation Id configured on field twitterUserId and one of its accessor methods in class TwitterFollowerCount!
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. 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()
    2. Spring Data Core
      AnnotationBasedPersistentProperty.<init>
      1. org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.populateAnnotationCache(AnnotationBasedPersistentProperty.java:86)[spring-data-commons-1.5.1.RELEASE.jar:na]
      2. org.springframework.data.mapping.model.AnnotationBasedPersistentProperty.<init>(AnnotationBasedPersistentProperty.java:62)[spring-data-commons-1.5.1.RELEASE.jar:na]
      2 frames
    3. Spring Data MongoDB - Core
      MongoMappingContext.createPersistentProperty
      1. org.springframework.data.mongodb.core.mapping.BasicMongoPersistentProperty.<init>(BasicMongoPersistentProperty.java:73)[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      2. org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty.<init>(CachingMongoPersistentProperty.java:44)[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      3. org.springframework.data.mongodb.core.mapping.MongoMappingContext.createPersistentProperty(MongoMappingContext.java:65)[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      4. org.springframework.data.mongodb.core.mapping.MongoMappingContext.createPersistentProperty(MongoMappingContext.java:37)[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      4 frames
    4. Spring Data Core
      AbstractMappingContext$PersistentPropertyCreator.doWith
      1. org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:391)[spring-data-commons-1.5.1.RELEASE.jar:na]
      1 frame
    5. Spring Core
      ReflectionUtils.doWithFields
      1. org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:570)[spring-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]
      1 frame
    6. Spring Data Core
      AbstractMappingContext.getPersistentEntity
      1. org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:283)[spring-data-commons-1.5.1.RELEASE.jar:na]
      2. org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:190)[spring-data-commons-1.5.1.RELEASE.jar:na]
      3. org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:159)[spring-data-commons-1.5.1.RELEASE.jar:na]
      4. org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:69)[spring-data-commons-1.5.1.RELEASE.jar:na]
      4 frames
    7. Spring Data MongoDB - Core
      MongoTemplate.findAll
      1. org.springframework.data.mongodb.core.MongoTemplate.determineCollectionName(MongoTemplate.java:1607)[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      2. org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1058)[spring-data-mongodb-1.2.1.RELEASE.jar:na]
      2 frames