Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specification of the classloader for [de]serialisation #555

Closed
gravelld opened this issue Aug 7, 2015 · 3 comments
Closed

Allow specification of the classloader for [de]serialisation #555

gravelld opened this issue Aug 7, 2015 · 3 comments

Comments

@gravelld
Copy link

gravelld commented Aug 7, 2015

See also #377 .

When MapDB [de]serialises objects, it needs to load the classes each object implements.

In a Java app running in a vanilla application container, using Class.forName is sufficient for this, because there is no class scope and all classes are known to all classes.

In an OSGi container, the scope is far more constrained. MapDB is deployed as its own "bundle" and using Class.forName will only work to load classes in the packages that the MapDB bundle has been pre-configured to know about.

This is a problem common with ORMs. The problem is more eloquently and authoritatively described in http://njbartlett.name/2010/08/30/osgi-readiness-loading-classes.html . Three solutions are suggested.

For my own use, I have hacked MapDB to have a setClassloader method on DBMaker which is passed through to the serialisation layer. This is then used for loading classes, and it works well. However, whoever does this work for MapDB should consider which of the three options presented above makes most sense from MapDB's perspective.

@jankotek
Copy link
Owner

jankotek commented Aug 7, 2015

I will have a look, thanks for good documentation.

On August 7, 2015 5:57:25 PM CEST, gravelld notifications@github.com wrote:

See also #377 .

When MapDB [de]serialises objects, it needs to load the classes each
object implements.

In a Java app running in a vanilla application container, using
Class.forName is sufficient for this, because there is no class scope
and all classes are known to all classes.

In an OSGi container, the scope is far more constrained. MapDB is
deployed as its own "bundle" and using Class.forName will only work to
load classes in the packages that the MapDB bundle has been
pre-configured to know about.

This is a problem common with ORMs. The problem is more eloquently and
authoritatively described in
http://njbartlett.name/2010/08/30/osgi-readiness-loading-classes.html .
Three solutions are suggested.

For my own use, I have hacked MapDB to have a setClassloader method
on DBMaker which is passed through to the serialisation layer. This
is then used for loading classes, and it works well. However, whoever
does this work for MapDB should consider which of the three options
presented above makes most sense from MapDB's perspective.


Reply to this email directly or view it on GitHub:
#555

@jankotek
Copy link
Owner

MapDB now allows to set custom global class loader and per-class class loader.

There are new methods in DBMaker:

This will set default Class Loader for all classes instantiated during deserialization:
serializerClassLoader(loader)

And this will set Class Loader for specific class:
.serializerRegisterClass(classname,loader)

@gravelld
Copy link
Author

Thanks, that will be very easy for me to port to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants