升级到 spring boot 2.2.X 后出现 MappingException(Attempt to add id) [英] MappingException(Attempt to add id) after upgrading to spring boot 2.2.X

查看:34
本文介绍了升级到 spring boot 2.2.X 后出现 MappingException(Attempt to add id)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 spring boot 升级到 2.2.4(从 2.1.x)后,将 org.springframework.cloud:spring-cloud-dependencies 升级到 Hoxton.RELEASE,将 org.springframework.cloud:spring-cloud-stream-dependencies 升级到 Horsham.发布.

After upgrading the spring boot to 2.2.4 (from 2.1.x), org.springframework.cloud:spring-cloud-dependencies to Hoxton.RELEASE and org.springframework.cloud:spring-cloud-stream-dependencies to Horsham.RELEASE.

尝试创建索引文档时出现以下异常.

Getting the following exception when trying to create index document.

Caused by: org.springframework.data.mapping.MappingException: Attempt to add id property private java.util.Map .CatalogIndex.document 但已经将属性 private java.lang.String .CatalogIndex.id 注册为 id.检查您的映射配置!

Caused by: org.springframework.data.mapping.MappingException: Attempt to add id property private java.util.Map .CatalogIndex.document but already have property private java.lang.String .CatalogIndex.id registered as id. Check your mapping configuration!

请找到实体类层次结构.为简单起见,我删除了所有的 getter 和 setter.

Please find the entity class hierarchy. I have removed all the getter and setter for simplicity.

package mypackage.entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Parent;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class CatalogIndex {

    private static final long serialVersionUID = 1L;

    @Id
    private String id;

    @Parent(type = "Initiative")
    private String initiativeId;

    private List<Map<String, Object>> typeHierarchy;

    private Map<String, Object> document;

    private List<Map<String, Object>> filters;
}

<小时>

package mypackage.entity;

import org.springframework.data.elasticsearch.annotations.Document;

@Document(indexName = "cataloginitiative")
public class CatalogInitiativeIndex extends CatalogIndex {   }

<小时>

推荐答案

Spring Data Elasticsearch,在检查 Entity 类时,试图找出该类的哪个属性将用作 Id财产.如果以下情况之一为真,则属性符合此条件:

Spring Data Elasticsearch, when inspecting the Entity class, tries to figure out which property of the class is to be used as the Id property. A property qualifies for this if one of the following is true:

  • 该属性使用 @Id
  • 进行注释
  • 该属性名为 id
  • 该属性名为document

因此,在您的情况下,您拥有具有匹配名称和注释的属性 id,以及具有匹配名称的属性 document.

So in your case you have the property id which has a matching name and the annotation, and the property document with a matching name.

您必须将您的属性document 重命名为不同的名称.

You have to rename your property document to somthing different.

这篇关于升级到 spring boot 2.2.X 后出现 MappingException(Attempt to add id)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆