3

Getting the following Exception in my spring boot mongo application

Caused by: org.springframework.data.mapping.model.MappingException: Ambiguous field mapping detected! Both private final java.lang.reflect.Type org.springframework.data.util.TypeDiscoverer.type and private final java.lang.Class org.springframework.data.util.ClassTypeInformation.type map to the same field name type! Disambiguate using @Field annotation! at org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity$AssertFieldNameUniquenessHandler.assertUniqueness(BasicMongoPersistentEntity.java:296) ~[spring-data-mongodb-1.10.7.RELEASE.jar:na] at org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity$AssertFieldNameUniquenessHandler.doWithPersistentProperty(BasicMongoPersistentEntity.java:283) ~[spring-data-mongodb-1.10.7.RELEASE.jar:na] at org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity$AssertFieldNameUniquenessHandler.doWithPersistentProperty(BasicMongoPersistentEntity.java:277) ~[spring-data-mongodb-1.10.7.RELEASE.jar:na] at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:330) ~[spring-data-commons-1.13.7.RELEASE.jar:na] at org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity.verifyFieldUniqueness(BasicMongoPersistentEntity.java:157) ~[spring-data-mongodb-1.10.7.RELEASE.jar:na] at org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity.verify(BasicMongoPersistentEntity.java:149) ~[spring-data-mongodb-1.10.7.RELEASE.jar:na] at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:332) ~[spring-data-commons-1.13.7.RELEASE.jar:na]

The thing is none of those fields("type") are under my control. Need help in this.

import org.springframework.data.mongodb.repository.MongoRepository;

import com.xyz.abc.core.model.ConfigEntity;

/**
 * 
 * @author asdasd.asdafsfg
 *
 */
public interface ConfigRepository extends MongoRepository<ConfigEntity, String> {

    public ConfigEntity findById(String id);

}

My ConfigEntity.java looks like this

import java.io.Serializable;
import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.Association;
import org.springframework.data.mongodb.core.mapping.Document;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 
 * @author vinay.shivanna
 *
 */
@Data
@NoArgsConstructor
@Document(collection="configstore")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ConfigEntity implements Serializable {

    private static final long serialVersionUID = -5484736588242242417L;

    @Id
    private String id;

    @NotNull
    @JsonProperty("defaultAssociations")
    private List<Association> defaultAssociations;

    @NotNull
    @JsonProperty("profileAssociations")
    private List<Association> profileAssociations;

}

I am using spring mongo starter dependency

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>

Spring boot version is 1.5.7.RELEASE

I se that Association class which is coming from spring-data-commons-1.13.7-RELEASE jar is extending a class PersistentProperty which internally extends itself.. like this PersistentProperty<P extends PersistentProperty<P>> This class has type Property.Thats the one which is given in the stacktrace.. But i really don't have the solution. Need help

Thanks in advance

stallion
  • 1,901
  • 9
  • 33
  • 52
  • can you show the full tack trace. Do you have any inheritance between your entities. Did you check these https://stackoverflow.com/questions/46120786/mappingexception-ambiguous-field-mapping-detected and https://jira.spring.io/browse/DATAMONGO-694 – pvpkiran Jan 24 '18 at 15:03
  • added full stack trace.. i dont have any inheritance.. i have put the complete referenced java content of all the related classes – stallion Jan 24 '18 at 15:53
  • @pvpkiran added some more details upon debugging.. You were right of the inheritance part of it.. – stallion Jan 25 '18 at 07:20
  • 1
    how was this fixed? – Ido Barash May 27 '20 at 07:30
  • Having a similar problem with DB2 classes. – Nirro Sep 02 '20 at 08:45

0 Answers0