PDA

View Full Version : Spring Data Graph: Avoiding Class.forName



ractive
Aug 2nd, 2011, 04:49 PM
Hello everyone

The IndexingNodeTypeRepresentationStrategy is using Class.forName() to load classes for which its type is stored in the _type_ property on nodes. Class.forName() has well known limitations in OSGi and J2EE environments. A very nice article with some solutions about this issue can be found in this blog post (http://njbartlett.name/2010/08/30/osgi-readiness-loading-classes.html).

In this pull-request (https://github.com/SpringSource/spring-data-graph/pull/5) I proposed to use the DynamicImport-Package directive to have the Spring Data Graph framework dynamically import domain classes in OSGi, so that they can be loaded with Class.forName(). I think that this should be seen as a workaround for now and that a more OSGi-friendly solution should be found.

Without knowing the internals of SDG, I could imagine that the class registration solution that is shown in option 2 in the mentioned blog post could be used here quite well. Could maybe the generated repository register its type in the SDG framework upon its creation so that the IndexingNodeTypeRepresentationStrategy could query the registered classes first and then fall back to Class.forName()?


Best regards,
James

MichaelHunger
Aug 3rd, 2011, 04:42 AM
Right, we could have a register className -> class in the graphdatabasecontext anyway. That could then be used by different facilities, like the indexing service, the entity-instatiator and the mapping context. Right now we get each type when it is instantiated first time, that might be a bit late. So we have to have a means that works in all contexts. I don't know how well Spring Classpath scanning works in a OSGi context.

Cheers
Michael