Morphia在保存基本实体时抛出内部异常

时间:2016-09-09 13:25:36

标签: java mongodb morphia

我一直试图用Morphia保存一个POJO而没有运气。我有以下代码,这很简单:

final Morphia morphia = new Morphia();

morphia.mapPackage("entities.users");

final Datastore datastore = morphia.createDatastore(new MongoClient(), "test_table");
datastore.ensureIndexes();
datastore.save(user);

然而,奇怪的是datastore.ensureIndexes()抛出了一个奇怪的内部异常,取决于Morphia:

WARNING: Parameterized types are treated as untyped Objects. See field 'assertionLock' on class java.lang.ClassLoader
org.mongodb.morphia.mapping.MappingException: Cannot use non-static inner class: class java.security.ProtectionDomain$Key. Please make static.
    at org.mongodb.morphia.mapping.MappedClass.basicValidate(MappedClass.java:495)
    at org.mongodb.morphia.mapping.MappedClass.<init>(MappedClass.java:123)
    at org.mongodb.morphia.mapping.Mapper.getMappedClass(Mapper.java:451)
    at org.mongodb.morphia.DatastoreImpl.processEmbeddedAnnotations(DatastoreImpl.java:1545)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1185)
    at org.mongodb.morphia.DatastoreImpl.processEmbeddedAnnotations(DatastoreImpl.java:1545)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1185)
    at org.mongodb.morphia.DatastoreImpl.processEmbeddedAnnotations(DatastoreImpl.java:1545)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1185)
    at org.mongodb.morphia.DatastoreImpl.processEmbeddedAnnotations(DatastoreImpl.java:1545)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1185)
    at org.mongodb.morphia.DatastoreImpl.processEmbeddedAnnotations(DatastoreImpl.java:1545)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1185)
    at org.mongodb.morphia.DatastoreImpl.processEmbeddedAnnotations(DatastoreImpl.java:1545)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1185)
    at org.mongodb.morphia.DatastoreImpl.processEmbeddedAnnotations(DatastoreImpl.java:1545)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1185)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1167)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1189)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:274)
    at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:266)
    at repositories.UsersRepository.createUser(UsersRepository.java:65)
    at repositories.UsersRepository.main(UsersRepository.java:101)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code 0

1 个答案:

答案 0 :(得分:0)

在某种程度上,您正在尝试序列化一个java.security.ProtectionDomain$Key实例,而Morphia和驱动程序都不知道如何操作。您需要编写Converter来管理该类型。