简体   繁体   English

“IllegalArgumentException:java.util.HashMap 类型的目标 bean 不是持久实体的类型”当使用嵌入文档时

[英]"IllegalArgumentException: Target bean of type java.util.HashMap is not of type of the persistent entity" When using embedded document

I am upgrading from spring-boot 1.5.10 to 2.1.1.我正在从 spring-boot 1.5.10 升级到 2.1.1。 However, I get following error "IllegalArgumentException: Target bean of type java.util.HashMap is not of type of the persistent entity".但是,我收到以下错误“IllegalArgumentException:java.util.HashMap 类型的目标 bean 不是持久实体的类型”。

Here are my classes:这是我的课程:

@Document
public class AbstractMongoDocument extends AbstractPersistable<String> {

  private static final long serialVersionUID = 1621100881694109722L;

  @CreatedDate
  private DateTime creationDate;

  @LastModifiedDate
  private DateTime modificationDate; 
}


public abstract class AbstractAuditableMongoDocument extends AbstractMongoDocument {

  private static final long serialVersionUID = 4962248712372390885L;

  @Version
  private Long version;

  @LastModifiedBy
  private String updatedBy;


  @CreatedBy
  private String createdBy;

}


public class Email extends AbstractAuditableMongoDocument {

  private static final long serialVersionUID = 7601333678154632864L;

  private String hashedEmail;

  public Email() {
  }

  public Email(
        String hashedEmail) {
    this.hashedEmail = hashedEmail;
}


@Validated
@Document
public class Account extends AbstractMongoDocument {

  private static final long serialVersionUID = -8228412296744241027L;

  @Indexed(unique = true)
  protected String primaryEmail;

  Map<String, Email> emails = new HashMap<>();
}

This set up worked fine on 1.5.10 with mongodb but no longer does and is throwing the java.lang.IllegalArgumentException mentioned above.这个设置在 1.5.10 上使用 mongodb 运行良好,但不再有效并且正在抛出上面提到的 java.lang.IllegalArgumentException。

You have to change your type from long to Long.您必须将类型从 long 更改为 Long。

Long is an object and it can be serialized/deserialized via the java serialization mechanism. Long 是一个对象,它可以通过 java 序列化机制进行序列化/反序列化。

Same thing if you have HashMap in your model it should be just Map.同样的事情,如果你的模型中有 HashMap,它应该只是 Map。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalArgumentException:未找到类型为java.util.HashMap的返回值的转换器 - java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.HashMap FirebaseRecyclerAdapter 但无法将 java.util.HashMap 类型的值转换为字符串? - FirebaseRecyclerAdapter but Failed to convert value of type java.util.HashMap to String? 无法将java.util.HashMap类型的值转换为String - Failed to convert value of type java.util.HashMap to String 未找到类型为java.util.HashMap的返回值的转换器 - No converter found for return value of type: class java.util.HashMap JAXB无法封送类型“ java.util.HashMap” - JAXB unable to marshal type “java.util.HashMap” 参数1的类型为java.util.TreeMap,得到了java.util.HashMap - argument 1 has type java.util.TreeMap, got java.util.HashMap 无法将类型java.util.HashMap的值转换为String,但是代码中没有哈希图? - Failed to convert value of type java.util.HashMap to String but no hashmap in code? 当我尝试从 firebase 检索数据到 viewpager2 时,无法将 java.util.HashMap 类型的值转换为字符串错误 - Failed to convert value of type java.util.HashMap to String error when I'm trying to retrieve data from firebase to viewpager2 找不到媒体类型 = 应用程序/xml,类型 = 类 java.util.HashMap$Values 的 MessageBodyWriter - MessageBodyWriter not found for media type=application/xml, type=class java.util.HashMap$Values 错误未检查调用 &#39;put(K, V)&#39; 作为原始类型 &#39;java.util.HashMap&#39; 的成员 - Error Unchecked call to 'put(K, V)' as a member of raw type 'java.util.HashMap'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM