+1  A: 

My earlier comment as an answer:

This exception indicates that it is a class loader issue. Compare the class-loader of the object and the class you're using for the cast.

ClassLoader loaderOfObject = theObject.getClass().getClassLoader(); ClassLoader loaderOfLocalClass = MyClass.getClassLoader(); // have to be the same. assert loaderOfObject.equals(loaderOfLocalClass);

Btw: If db4o is using the wrong class-loader. You can change that by configuring the class-loader explicit.

    EmbeddedConfiguration configuration = Db4oEmbedded.newConfiguration();
    JdkReflector reflector = new JdkReflector(Thread.currentThread().getContextClassLoader());
    configuration.common().reflectWith(reflector);
    ObjectContainer container = Db4oEmbedded.openFile(configuration, "database.db4o");

When a single class-loader isn't enough: You can also pass a instance of the db4o-interface JdkLoader instead of a class-loader. In there you can implement any class-lookup method. For example to look up in multiple class loaders.

Gamlor