Hi Gonzalo, I've used Hibernate in Karaf in the past got it al working based on on Hibernate bundles created as described in this blog post: http://iocanel.blogspot.nl/2010/07/wicket-spring-3-jpa2-hibernate-osgi.html
I was able to update these bundles to Hibernate 3.6.2 but switched to OpenJPA after all. Regards, Bram 2013/1/29 Jean-Baptiste Onofré <[email protected]>: > Hi Gonzalo, > > my comments inline: > > >> First. >> Why do we have to repackage every library is not in the form of >> bundle? >> It would be easier, more manageable, to wrap missing libraries (not >> in the form of a bundle) around a container that describes its contents. >> This way something like, say, apache.commons does not need to be >> unpacked and packed with a new manifiest. This method will break signing >> if any, but proposed one does not. > > A lot of library (like commons) are already bundles. > The problem using wrap is that most of the time the OSGi statements are not > correct. That's why creating a bundle is required. > > >> >> >> Second. >> This project (in this case OSGi-> Felix) is supposed to be created >> to resolve library mess. But I can only find references to peculiarities >> to the implementation of the class loaders that makes every old project >> incompatible without modifications. Say Hibernate. Do I have to use >> packages that only springsource Enterprise provides? This is a little >> pain because if the bundle is not there, is not anywhere. > > Karaf is an OSGi container. Classloaders are handled in a different way in > OSGi. > > >> >> >> Third. >> After fighting with dependencies for a long time. I repackaged >> hibernate, spring and friend into a new package. And found that nothing >> works together. I was smart enough to get spring 3.0.7-RELEASE that >> comes with karaf. But found following problem that I'm not able to >> solve: > > Creating a "big" bundle mean that you create a single classloader. It works > but it's ugly IMHO. > Fragment can do the trick too. > > I'm not sure to follow your issues with Hibernate and Spring. > > Regards > JB > > > >> >> >> But the class org/hibernate/cfg/Configuration is packaged with the rest. >> And it must find it. Where is the problem? >> >> I tried package different versions of hibernate that is the thing that I >> can touch. Because Spring is too much to repackage it. So I have to >> stick with the two versions included in the container, 3.0.7-RELEASE and >> 3.1 whatever. >> >> Any help on how to make it work? >> >> >> I read everywhere: Switch to openJPA it does bundles and works better >> with OSGi. But I just have much built on hibernate and don't want to >> switch. I want to learn how to make every project work. Don't want to >> have to do a switch to another project everytime I have some missing >> package (bundle) that makes the project not to work on osgi. >> >> Thank you in advance. >> It will be a great project once this kind of problems are solved. In >> effect cxf works great! >> >> >> ----------------------------------- >> >> Exception in thread "SpringOsgiExtenderThread-4" >> org.springframework.beans.factory.BeanCreationException: Error creating >> bean with name 'crmSessionFactoryBean' defined in URL >> [bundle://196.0:0/META-INF/spring/hibernate-spring-beans.xml]: >> Instantiation of bean failed; nested exception is >> org.springframework.beans.BeanInstantiationException: Could not >> instantiate bean class >> [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: >> Constructor threw exception; nested exception is >> java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration >> at >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:964) >> at >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:910) >> at >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:484) >> at >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) >> at org.springframework.beans.factory.support.AbstractBeanFactory >> $1.getObject(AbstractBeanFactory.java:293) >> at >> >> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) >> at >> >> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) >> at >> >> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) >> at >> >> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567) >> at >> >> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) >> at >> >> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69) >> at >> >> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355) >> at >> >> org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85) >> at >> >> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320) >> at >> >> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132) >> at java.lang.Thread.run(Thread.java:679) >> Caused by: org.springframework.beans.BeanInstantiationException: Could >> not instantiate bean class >> [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: >> Constructor threw exception; nested exception is >> java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration >> at >> org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141) >> at >> >> org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74) >> at >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:957) >> ... 15 more >> Caused by: java.lang.NoClassDefFoundError: >> org/hibernate/cfg/Configuration >> at >> >> org.springframework.orm.hibernate3.LocalSessionFactoryBean.<init>(LocalSessionFactoryBean.java:189) >> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native >> Method) >> at >> >> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) >> at >> >> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) >> at >> java.lang.reflect.Constructor.newInstance(Constructor.java:532) >> at >> org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126) >> ... 17 more >> >> > > -- > Jean-Baptiste Onofré > [email protected] > http://blog.nanthrax.net > Talend - http://www.talend.com
