如何将 log4mongo 文档映射到 java 对象
基本上我的 log4mongo 正在记录用户活动,我想选择 一个用户并查看他的日志条目,
此代码工作正常,
BasicDBObject blogEntryDbObj = (BasicDBObject)
mongo.getDB().getCollection("log").findOne(new BasicDBObject("_id",
new ObjectId(blogEntryId)));
但在这里我收到错误“尝试映射到未映射的类:
log = morphia.fromDBObject(log.class, blogEntryDbObj);
日志
的包
名称应该是什么” > 类或者也许是那个 是无关紧要的。我意识到我的 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;
}
Basically my log4mongo is logging user activity and i want to select
one user and view his log entries,
This code is working ok
BasicDBObject blogEntryDbObj = (BasicDBObject)
mongo.getDB().getCollection("log").findOne(new BasicDBObject("_id",
new ObjectId(blogEntryId)));
but here im getting the error "Trying to map to an unmapped class:
log = morphia.fromDBObject(log.class, blogEntryDbObj);
What should the package
name be for the log
class or maybe that
is irrelevant. I realize that probably my POJO is not correctly set up
but i cannot figure out what's wrong.
The log4mongo document look like this.
{
"_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"
}
}
Here is my POJO im trying to map to
@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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
morphia.map
是实例方法。您需要在 Morphia 的同一个实例上morphia.map
才能使morphia.fromDBObject
正常工作morphia.map
is instance method. You need tomorphia.map
it on the same instance of Morphia to getmorphia.fromDBObject
to work