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;
}
morphia.map
is instance method. You need to morphia.map
it on the same instance of Morphia to get morphia.fromDBObject
to work