Hello everyone,
I am writing a Plugin-based webapp for my diploma thesis. The plugins are loaded by the Java Plugin Framework[1]. There is one classloader per plugin, which handles all the plugins classes. The classloader hirarchy is the same as for the plugins (e.g. if plugin B depends on plugin A, that means that As classloader is a parent of Bs) and the classloader of the host application is the root.
What I wish to do is to scan for and iterate through the plugins and add the mapping for the entity class of the current plugin (there's just one per plugin) to my hibernate configuration.
Here's my problem: Although I can receive the mapping files from the plugins (i.e. the InputStream) and add them to the config, I cannot create the SessionFactory, because Hibernate cannot find the entity classes :-(
I looked at the source and it seems that hibernate always uses Thread.currentThread().getContextClassLoader() to load the classes.
Is there no way to tell hibernate which classloader to use for each class? I have references to all the plugin-classloaders, so it wouldn't be a problem to somehow add them to the configuration.
Should I set the contextClassLoader using Thread.currentThread().setConfigClassLoader() to some custom classloader (that knows all plugin entity classes) before calling buildSessionFactory() and restore the old one afterwards? Or will it mess everything up then?
Thanx for you help!
~Andreas
[1]
http://jpf.sourceforge.net/
Hibernate version: 3.3.1.GA
Full stack trace of any exception that occurs:
org.hibernate.MappingException: entity class not found: de.uka.ipd.taxor.plugins.hbm.type.plain.TaxorPlain
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:122)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:154)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:457)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:113)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:87)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:261)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
at de.uka.ipd.taxor.plugins.hbm.CoreServiceFactoryImpl.getSessionFactory(CoreServiceFactoryImpl.java:58)
at de.uka.ipd.taxor.plugins.hbm.CoreServiceFactoryImpl.getCoreService(CoreServiceFactoryImpl.java:188)
at de.uka.ipd.taxor.ResourceManagerListener.getServiceObject(ResourceManagerListener.java:137)
at de.uka.ipd.taxor.ResourceManagerListener.contextInitialized(ResourceManagerListener.java:164)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.ClassNotFoundException: de.uka.ipd.taxor.plugins.hbm.type.plain.TaxorPlain
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:123)
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:119)
... 25 more
Name and version of the database you are using: HSQLDB 1.8.0.10