ClassNotFoundException after renaming of a package containing the interesting Entity annotated class
I renamed a package, containing class A. My Morphia dao use class A. Building locally the project is ok, so testing it, but at runtime, on the server, it throws
apr 19, 2013 12:02:04 AM com.github.jmkgreen.morphia.mapping.DefaultCreator getClass
Avvertenza: Class not found defined in dbObj:
Why? I tried the solution described here: https://code.google.com/p/morphia/issues/detail?id=208 but MongoBundleActivator class seems to not exist, neither in Morphia neither in Mongo Java Driver.
Furthermore, the class is loaded, but the exception is still throwed.
I'm having the same problem. It's easy to reproduce: create a new class TheEntity and save an instance to Mongo using the Datastore.
Then rename the TheEntity to EntityRenamed and try to run datastore.find(EntityRenamed.class).asList(). You'll get the object but also get an exception like this:
ADVERTENCIA: Class not found defined in dbObj:
java.lang.ClassNotFoundException: example.TheEntity
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
When I inspected the database using Mongo express, I've found that Morphia is adding the class name as data:
{
"_id": ObjectID("572fd70f5314f87a136e973f"),
"className": "example.TheEntity",
"name": "A name"
}
So after renaming the entity you may have to update your database.
By running a search on Google I've found that adding the className attribute is done by design and is actually a functionality.
If you don't need that functionality (read about it here) then you can disable it using noClassnameStored=true like it's explained in the documentation
hello, guys, i met same problem, we have to change the java file location, now we have to update enormous records classname in database to new value for compatability? that's ridiculous!