基本上我的log4mongo正在记录用户活动,我想选择 一个用户并查看他的日志条目,
此代码正常运行
BasicDBObject blogEntryDbObj = (BasicDBObject)
mongo.getDB().getCollection("log").findOne(new BasicDBObject("_id",
new ObjectId(blogEntryId)));
但是我在这里得到错误“试图映射到未映射的类:
log = morphia.fromDBObject(log.class, blogEntryDbObj);
package
类的log
名称应该是什么?
是无关紧要的。我意识到可能我的POJO没有正确设置
但我无法弄清楚出了什么问题。
log4mongo文档看起来像这样。
{
"_id" : ObjectId("4eecf4e4f9cb90f308193614"),
"timestamp" : new Date("Sat, 17 Dec 2011 21:00:36 GMT +01:00"),
"level" : "INFO",
"thread" : "Server.Connection:146.53.243.167:4570",
"message" : "setting RegistrationId for: zambe",
"loggerName" : {
"fullyQualifiedClassName" : "zambe.afa8cc37-4796-49c1-
a175-05a8daf0a88c",
"package" : ["zambe", "afa8cc37-4796-49c1-a175-05a8daf0a88c"],
"className" : "afa8cc37-4796-49c1-a175-05a8daf0a88c"
},
"fileName" : "PushUpdateRegistrationId.java",
"method" : "connect",
"lineNumber" : "61",
"class" : {
"fullyQualifiedClassName" :
"com.carlsberg.server.PushUpdateRegistrationId",
"package" : ["com", "carlsberg", "server",
"PushUpdateRegistrationId"],
"className" : "PushUpdateRegistrationId"
},
"host" : {
"process" : "5832@ERIKSWEDMINI",
"name" : "ERIKSWEDMINI",
"ip" : "192.168.1.150"
}
}
这是我的POJO我试图映射到
@Entity(value = "log")
public class log
{
@Id private ObjectId id;
Date timestamp;
Level level;
String thread;
String message;
@Embedded
LoggerName loggerName;
String fileName;
String method;
String lineNumber;
@Embedded("class")
LoggerClass loggerClass;
@Embedded
MyHost host;
}
@Entity(noClassnameStored=true)
@Embedded
class LoggerName
{
String fullyQualifiedClassName;
@Property("package")
String[] _package;
String className;
}
@Entity(noClassnameStored=true)
@Embedded
class LoggerClass
{
String fullyQualifiedClassName;
@Property("package")
String[] _package;
String className;
}
@Entity(noClassnameStored=true)
@Embedded
class MyHost
{
String process;
String name;
String ip;
}
答案 0 :(得分:1)
morphia.map
是实例方法。您需要morphia.map
在Morphia的同一个实例上morphia.fromDBObject
才能让{{1}}工作