-
1. Re: Module dependecy clashing
thomas.diesler Aug 27, 2012 9:14 AM (in response to sbesada)The hibernate team is currently working on an OSGi enabled version of their stuff. In the context of AS7 we are looking at Enterprise OSGi JPA. Please monitor/vote on
https://issues.jboss.org/browse/AS7-5405
It's high on my priority list and the first approach will probably be to get this working with the OpenJPA provider. Later we will hopefully be able to use the Hibernate provider.
-
2. Re: Module dependecy clashing
sbesada Aug 31, 2012 8:06 AM (in response to thomas.diesler)Hi,
I'm sending you a setup with two errors. The first one is one in which JBoss does't find the persistence context because the bundle javax.persistence uses Thread.currentThread().getContextClassLoader() to load the persistence provider but Thread.currentThread().getContextClassLoader() is null because Jboss sets to null this classLoader. To solve this problem in our example we have set the contextClassLoader to the bundles' classLoader in the bundle: telvent-tp-jboss-persistence, class:IPPersistenceServiceImpl, line 45 (Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader())). The bundle telvent-tp-jboss-persistence calls javax.persistence and now it properly finds the providers.
This error, Thread.currentThread().getContextClassLoader() == null, happens in whatever bundle that make use of Thread.currentThread().getContextClassLoader().
private static void findAllProviders() throws IOException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Enumeration<URL> resources =
loader.getResources("META-INF/services/" + PersistenceProvider.class.getName());
Set<String> names = new HashSet<String>();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
InputStream is = url.openStream();
try {
names.addAll(providerNamesFromReader(new BufferedReader(new InputStreamReader(is))));
} finally {
is.close();
}
}
for (String s : names) {
try{
providers.add((PersistenceProvider)loader.loadClass(s).newInstance());
} catch (ClassNotFoundException exc){
} catch (InstantiationException exc){
} catch (IllegalAccessException exc){
}
}
}
The second error hst to do with logging. We are using the slf4-framework like jboss, but jboss-osgi loads in first place slf4j-module from its configured modules. For this reason, our bundles are forced to use the same log that jboss is using. Bundles that use Dynamic-Import use our log, along with jboss' log.
-
sources.rar.zip 28.9 KB
-
jboss.rar.zip 13.5 MB
-
-
3. Re: Module dependecy clashing
sbesada Aug 31, 2012 8:55 AM (in response to sbesada)Hi,
In the last example that I have send you, if you set the contextClassLoader to the bundles' classLoader in the bundle: telvent-tp-jboss-persistence, the example works properly but the provider has to be in the same bundle (telvent-tp-jboss-persistence) because if you use a fragment, for instace, Jboss doesn't find the provider.