-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Plugin application : Classes have different classloaders
PostPosted: Sun Dec 21, 2008 2:16 pm 
Newbie

Joined: Sun Dec 21, 2008 1:12 pm
Posts: 2
Location: Karlsruhe, Germany
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


Top
 Profile  
 
 Post subject: SOLVED
PostPosted: Wed Jan 21, 2009 8:55 pm 
Newbie

Joined: Sun Dec 21, 2008 1:12 pm
Posts: 2
Location: Karlsruhe, Germany
Just in case anyone else is interested: What I mentioned in the last paragraph solved the problem:

Write a custom classloader that "sees" all the classes and set it as ContextClassLoader before the creation of the SessionFactory. (I also hat to restore the old ContextClassLoader afterwards, because Tomcat was complaining...)

HTH
~Andreas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.