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
  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

  5. 0

    Annotations on RelationshipEntity methods not working

    GitHub | 2 years ago | freebim
    org.springframework.data.mapping.model.MappingException: No id property in class ...
  6. 0

    There is a model is like: {code:java} class Model { .... @DBRef List<OtherModel> members; ... } {code} and I need sliced access to the members variable. I use this query: {code:java} ObjectId objectId = new ObjectId("55c36f44f359d8a455a21f68"); Query query = new Query(Criteria.where("_id").is(objectId)); query.fields().slice("members", pageable.getOffset(), pageable.getPageSize()); List<Model> models = mongoTemplate.findOne(query, Model.class); {code} And I get this exception: {code:java} org.springframework.data.mapping.model.MappingException: No id property found on class class [Ljava.lang.Integer; at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:842) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:329) at org.springframework.data.mongodb.core.convert.QueryMapper.createDbRefFor(QueryMapper.java:460) at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:417) at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:378) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:257) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObjectForField(QueryMapper.java:200) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:123) at org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:1647) at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:563) at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:558) {code} where a field: {code:java} boolean needsAssociationConversion = property.isAssociation() && !keyword.isExists(); {code} 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 {code:java} keyword.isSlice() {code} check was done, everything works fine.

    Spring JIRA | 1 year ago | Zhu Hongshang
    org.springframework.data.mapping.model.MappingException: No id property found on class class [Ljava.lang.Integer;

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    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