Error in ensureIndexes() in 1.0.0

118 views
Skip to first unread message

david kilmer

unread,
Jun 10, 2015, 2:58:18 PM6/10/15
to mor...@googlegroups.com
I upgraded my project to use the new 1.0.0 driver and I'm getting the following error when Datastore.ensureIndexes() is called:

org.mongodb.morphia.mapping.MappingException: A type could not be found for the field null.null
at org.mongodb.morphia.mapping.MappedField.discoverType(MappedField.java:211)
at org.mongodb.morphia.mapping.MappedField.<init>(MappedField.java:101)
at org.mongodb.morphia.mapping.EphemeralMappedField.<init>(EphemeralMappedField.java:36)
at org.mongodb.morphia.mapping.MappedField.discoverType(MappedField.java:189)
at org.mongodb.morphia.mapping.MappedField.discover(MappedField.java:117)
at org.mongodb.morphia.mapping.MappedField.<init>(MappedField.java:95)
at org.mongodb.morphia.mapping.MappedClass.discover(MappedClass.java:214)
at org.mongodb.morphia.mapping.MappedClass.<init>(MappedClass.java:145)
at org.mongodb.morphia.mapping.Mapper.getMappedClass(Mapper.java:242)
at org.mongodb.morphia.DatastoreImpl.processEmbeddedAnnotations(DatastoreImpl.java:370)
at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:326)
at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:307)
at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:302)
at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:509)
at org.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:501)

I did notice that I get the following warning when starting up:

[my model class name] is using deprecated configuration options.  Please update to use the fields value on @Index

I looked for some documentation on using the Fields value (which seems to be an annotation with the unfortunate name "Field"), but I couldn't find anything.

Anyone know what could be causing the error?

Also - Is there a migration guide anywhere for upgrading to the 1.0 version? The converters got a little confusing, so I'm not sure if maybe my changes there are causing problems.

Justin Lee

unread,
Jun 10, 2015, 3:02:04 PM6/10/15
to mor...@googlegroups.com
This isn't technically an indexing error.  It's trying to map class it hasn't seen before and is getting tripped up.  It's probably a generics issue (that's the bulk of mapping errors these days).  Your best best is to set a break point in MappedClass and see which class and field it's trying to map.

--------------------------------

name     : "Justin Lee", 
  title    : "Software Engineer",
  twitter  : "@evanchooly",
  web      : [ "10gen.com", "antwerkz.com" ],
  location : "New York, NY" }

--
You received this message because you are subscribed to the Google Groups "Morphia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to morphia+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

david kilmer

unread,
Jun 11, 2015, 10:43:33 AM6/11/15
to mor...@googlegroups.com
Thanks for the assistance, Justin. I debugged through this, and it turns out that it's having trouble with an indexed field that uses a custom converter. There are generics involved.

Basically, our system uses a custom lazy loader. For a reference to another entity, we have a property like:

@Property("manager")
protected IdRef<Manager> manager;

We use a custom converter for IdRef<T> that just converts the property to and from ObjectId. In the case that's giving the error, the property is indexed.

I'm not sure if I should be doing something differently, or if this is a bug. Any thoughts?

David

Justin Lee

unread,
Jun 11, 2015, 10:48:34 AM6/11/15
to mor...@googlegroups.com
What does IdRef give you?  If you're just trying to store the id values in the db rather than embedding a document, you might look at the lazy and idOnly options on @Reference.

--------------------------------

name     : "Justin Lee", 
  title    : "Software Engineer",
  twitter  : "@evanchooly",
  web      : [ "10gen.com", "antwerkz.com" ],
  location : "New York, NY" }

david kilmer

unread,
Jun 11, 2015, 11:03:48 AM6/11/15
to mor...@googlegroups.com
IdRef gives us something very magical - it's actually a compound type that includes both an ID and a name. The name is retrieved from a cache (or from a "projection" via the mongo java driver when it's not in cache), because some overwhelming percentage of the time, the client's queries are to fill a grid, or - when they're modifying an object - to simply change the reference to refer to something else. In those cases, the ID is meaningless to the user, but the name associated with it is sufficient. We only go to the database for the reference when we're processing data and need to know some other property of the referenced object besides the name. This has resulted in a very, very big performance improvement for us.

We went custom on this, because even though it seemed like a typical enough use-case, the dependence on some sort of "name" field and the necessity of implementing a cache inclined us to believe this wasn't something that Morphia would ever do with its lazy-loading feature.

Anyway - it has worked swimmingly with previous versions of Morphia, so it feels like something that should be possible.

So do you think it's a bug?

Justin Lee

unread,
Jul 16, 2015, 2:02:43 PM7/16/15
to mor...@googlegroups.com
My apologies for losing this thread.  The mapping code has been getting lots of updates lately.  Could you try with the latest snapshot and see if that issue persists?  If so, please post a test case that recreates it and i'll see what I can do to fix it.  Thanks.

david kilmer

unread,
Jul 17, 2015, 5:57:57 PM7/17/15
to mor...@googlegroups.com
Hi, Justin. I'm still getting the same error in Morphia 1.0.1. Here's the smallest test case I could construct:

public class IdRef <T> {
 
public Class<T> modelClass;
 
public ObjectId id;


 
public IdRef() {
    modelClass
= null;
    id
= null;
 
}
 
 
public IdRef(Class<T> modelClass, ObjectId id) {
   
this.modelClass = modelClass;
   
this.id = id;
 
}
}


@Entity("test_referenced_model")
public class TestReferencedModel {
 
@Id

 
public ObjectId id;
}



@Entity("test_model")
public class TestModel {
 
@Id

 
public ObjectId id;
 
 
@Property("other")
 
public IdRef<TestReferencedModel> other;
}


 
public static void main(String[] args) {
   
try {
     
String dbHost = "localhost";
     
int dbPort = 27017;
     
String dbName = "testdb";
     
MongoClient mongo = new MongoClient(dbHost, dbPort);
     
Morphia morphia = new Morphia();
      morphia
.map(TestReferencedModel.class);
      morphia
.map(TestModel.class);
     
Datastore ds = ds = morphia.createDatastore(mongo, dbName);
      ds
.ensureIndexes();
   
} catch (Exception e) {
      log
.error(e.getMessage(), e);
   
}
 
}


The error occurs when ds.ensureIndexes called. The stack is:

org.mongodb.morphia.mapping.MappingException: A type could not be found for the field null.null
 at org
.mongodb.morphia.mapping.MappedField.discoverType(MappedField.java:211)
 at org
.mongodb.morphia.mapping.MappedField.<init>(MappedField.java:101)
 at org
.mongodb.morphia.mapping.EphemeralMappedField.<init>(EphemeralMappedField.java:36)
 at org
.mongodb.morphia.mapping.MappedField.discoverType(MappedField.java:189)
 at org
.mongodb.morphia.mapping.MappedField.discover(MappedField.java:117)
 at org
.mongodb.morphia.mapping.MappedField.<init>(MappedField.java:95)
 at org
.mongodb.morphia.mapping.MappedClass.discover(MappedClass.java:214)
 at org
.mongodb.morphia.mapping.MappedClass.<init>(MappedClass.java:145)
 at org
.mongodb.morphia.mapping.Mapper.getMappedClass(Mapper.java:242)

 at org
.mongodb.morphia.DatastoreImpl.processEmbeddedAnnotations(DatastoreImpl.java:364)
 at org
.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:320)
 at org
.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:302)
 at org
.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:297)
 at org
.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:496)
 at org
.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:488)

Thanks for your help.

David

david kilmer

unread,
Jul 17, 2015, 6:07:36 PM7/17/15
to mor...@googlegroups.com
I wasn't following your instructions closely. I was working with the latest release, not the latest snapshot. Here's the stack trace when I compile against the snapshot:

org.mongodb.morphia.mapping.MappingException: A type could not be found for the field null.null

 at org
.mongodb.morphia.mapping.MappedField.discoverType(MappedField.java:557)
 at org
.mongodb.morphia.mapping.MappedField.<init>(MappedField.java:107)
 at org
.mongodb.morphia.mapping.EphemeralMappedField.<init>(EphemeralMappedField.java:50)
 at org
.mongodb.morphia.mapping.MappedField.discoverType(MappedField.java:517)
 at org
.mongodb.morphia.mapping.MappedField.discover(MappedField.java:473)

 at org
.mongodb.morphia.mapping.MappedField.<init>(MappedField.java:95)

 at org
.mongodb.morphia.mapping.MappedClass.discover(MappedClass.java:524)
 at org
.mongodb.morphia.mapping.MappedClass.<init>(MappedClass.java:125)
 at org
.mongodb.morphia.mapping.Mapper.getMappedClass(Mapper.java:433)
 at org
.mongodb.morphia.DatastoreImpl.processEmbeddedAnnotations(DatastoreImpl.java:1503)
 at org
.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1150)
 at org
.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1132)
 at org
.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:1154)
 at org
.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:266)
 at org
.mongodb.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.java:258)

...
Reply all
Reply to author
Forward
0 new messages