Class not found defined in dbObj exception in OSGI

838 views
Skip to first unread message

Maarten

unread,
Feb 29, 2012, 12:57:15 PM2/29/12
to Morphia
Hi,

I'm trying to load some results from morphia, but outside the OSGI
container my tests run fine, but within it fails. I have the following
code:

myMorphia.map(ConfigurationEntity.class)
.map(GroupEntity.class)
.map(ObjectEntity.class)
.map(StructureEntity.class);

List<ConfigurationEntity> configurationEntityList =
myDataStore.find(ConfigurationEntity.class).asList();

I've tried 0.99 and the latest revision from the svn repository.

The stack trace is as follows:

WARNING: Class not found defined in dbObj:
java.lang.ClassNotFoundException: entity.ConfigurationEntity
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:
1516)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:
1361)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at
com.google.code.morphia.mapping.DefaultCreator.getClass(DefaultCreator.java:
84)
at
com.google.code.morphia.mapping.DefaultCreator.createInstance(DefaultCreator.java:
38)
at com.google.code.morphia.mapping.Mapper.fromDBObject(Mapper.java:
273)
at
com.google.code.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:
66)
at
com.google.code.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:
53)
at
com.google.code.morphia.query.MorphiaIterator.next(MorphiaIterator.java:
48)
at com.google.code.morphia.query.QueryImpl.asList(QueryImpl.java:264)

I hope anyone can shed some on it.

Regards,

Maarten

Scott Hernandez

unread,
Feb 29, 2012, 1:05:49 PM2/29/12
to mor...@googlegroups.com
What version are you using? You would have to do something like this:
http://code.google.com/p/morphia/issues/detail?id=208

Maarten

unread,
Feb 29, 2012, 1:11:16 PM2/29/12
to Morphia
I'm using the latest SVN trunk. Last checkout time was an hour ago.
I've looked at that issue, but it looks resolved in the current trunk.
Still, I'm getting those errors.

I forgot to mention that the morphia jar is not deployed as a bundle,
but it is included in the same bundle as the code in question.

Scott Hernandez

unread,
Feb 29, 2012, 1:19:30 PM2/29/12
to mor...@googlegroups.com
Are you overriding getClassLoaderPerClass in your ObjectFactory like
this (as shown in the issue)?

morphia.getMapper().getOptions().setObjectFactory(new DefaultCreator() {
@Override
protected ClassLoader getClassLoaderForClass(String
clazz, DBObject object) {
// we're the only bundle for now using Morphia so
we can be sure that in any case
// the classloader of this bundle has to be used
return MongoBundleActivator.getBundleClassLoader();
}
});

Maarten

unread,
Feb 29, 2012, 1:22:48 PM2/29/12
to Morphia
I just changed the following line in
com.google.code.morphia.mapping.DefaultCreator:

line 83:
try {
c = Class.forName(className);
} catch (ClassNotFoundException e) {

It was : c = Class.forName(className, true,
getClassLoaderForClass(className, dbObj));

getClassLoaderForClass only calls :
Thread.currentThread().getContextClassLoader();

This breaks the class loading in my Felix OSGI environment, so it
looks like this class loader is the problem. I'm not sure why, any
ideas?

Maarten

unread,
Feb 29, 2012, 2:33:55 PM2/29/12
to Morphia
Many thanks! This works and for some reason I missed that part from
the ticket. This completely solves the problem.

Regards,

Maarten
Reply all
Reply to author
Forward
0 new messages