[英]"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.