Classloader And Generic Classes

This topic applies to Java version only

db4o uses class information available from the classloader to store and recreate class objects. When a class definition is not available from the classloader db4o resolves to Generic Objects, which represent the class information stored in object arrays. With this approach db4o is ready to function both with and without class definitions available. However, the problem can appear when your application and db4o use different classloaders, because in this case db4o won't match objects in the database to their definitions in the runtime. In order to avoid this:

  1. Make sure that your db4o lib is not in JRE or JDK lib folder. Libraries in these folders get a special classloader, which is unaware of your application classes. Instead put db4o library into any other suitable for you location and make it available to your application through CLASSPATH or using IDE provided methods.
  2. If your application design does not guarantee that application classes and db4o will be loaded by the same classloader, use

    Configuration#reflectWith(new JdkReflector(classLoader))

    where classLoader is the classloader of your application classes.

The above-mentioned cases should be distinguished from a case when Java application uses a db4o database created from a .NET application. In this particular case .NET class definitions should be replaced by Java class definitions with the help of Aliases.