我正在尝试将动态JSON内容映射到Java对象,使用eclipse-link将其保存在Mongo数据库中,我使用Map如下
@Entity
@NoSql(dataFormat = DataFormatType.MAPPED)
public class MyCollection {
@Id
@GeneratedValue
@Field(name = "_id")
private String id;
@Temporal(TemporalType.TIMESTAMP)
@Field(name = "CreatedOn")
private Date createdOn;
@ElementCollection
@Field(name = "Attributes")
private Map<String, Object> attributes;
// Getters and Setters
}
但是它给出了错误
Exception [EclipseLink-7155] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The type [class java.lang.Object] for the attribute [attributes] on the entity class [class demo.MyCollection] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface.
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:115)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:188)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at test.Mongo.createEntityManager(Mongo.java:26)
at test.Mongo.<init>(Mongo.java:22)
at test.TestMongoOrm.<init>(TestMongoOrm.java:11)
at test.TestMongoOrm.main(TestMongoOrm.java:13)
任何想法如何解决这个问题?