Closed GoogleCodeExporter closed 9 years ago
Morphia doesn't save null for missing fields. How did this get it in there? Or
was it during loading?
You can ignore bad refs using this (see below), but I doubt it will fix this
problem. Please pose the full stack-trace.
@Reference(ignoreMissing=true)
Original comment by scotthernandez
on 25 Aug 2011 at 7:08
com.google.code.morphia.mapping.MappingException: Error mapping
field:br.com.digitaldoc.eatos.server.persistencia.mongo.pojos.UsuarioPojo.prefei
tura
at com.google.code.morphia.mapping.Mapper.toDBObject(Mapper.java:444)
at com.google.code.morphia.mapping.Mapper.toDBObject(Mapper.java:426)
at com.google.code.morphia.DatastoreImpl.entityToDBObj(DatastoreImpl.java:674)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:722)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:793)
at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:787)
at com.google.code.morphia.dao.BasicDAO.save(BasicDAO.java:109)
at br.com.digitaldoc.eatos.server.persistencia.mongo.dao.DaoUsuario.salvar(DaoUsuario.java:41)
at br.com.digitaldoc.eatos.server.persistencia.mongo.dao.DaoUsuario.salvar(DaoUsuario.java:1)
at br.com.digitaldoc.eatos.server.services.UsuarioServiceImpl.salvar(UsuarioServiceImpl.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: com.google.code.morphia.mapping.MappingException: @Id field cannot
be null!
at com.google.code.morphia.mapping.ReferenceMapper.getKey(ReferenceMapper.java:118)
at com.google.code.morphia.mapping.ReferenceMapper.writeSingle(ReferenceMapper.java:51)
at com.google.code.morphia.mapping.ReferenceMapper.toDBObject(ReferenceMapper.java:45)
at com.google.code.morphia.mapping.Mapper.writeMappedField(Mapper.java:529)
at com.google.code.morphia.mapping.Mapper.toDBObject(Mapper.java:442)
... 36 more
Original comment by caarlos0
on 25 Aug 2011 at 8:02
@Reference(ignoreMissing=true) doesn't work...
I'am usign morphia 0.99, don't know if it matters...
Original comment by caarlos0
on 25 Aug 2011 at 8:04
You need to set the @Id field for the referenced entities before you call save.
Caused by: com.google.code.morphia.mapping.MappingException: @Id field cannot
be null!
Original comment by scotthernandez
on 25 Aug 2011 at 10:30
but I don't want to save the reference, because the entire reference (Test2) is
null. When the reference is null, morphia should just ignore it (schemeless).
I don't want to save a empty bean.
Original comment by caarlos0
on 25 Aug 2011 at 11:37
The code seems pretty clear, if you pass in a null then you won't get this
error (or get far enough to cause this error). The error occurs if you pass an
entity without an @Id value. If you have a test case to show otherwise I can
add it to the tests.
Here is the code (where a NPE will happen if entity is null):
MappedClass mappedClass = mapr.getMappedClass(entity);
Object id = mappedClass.getIdField().get(entity);
if (id == null)
throw new MappingException("@Id field cannot be null!");
Original comment by scotthernandez
on 25 Aug 2011 at 11:53
Original issue reported on code.google.com by
caarlos0
on 25 Aug 2011 at 6:07