Announcement Announcement Module
Collapse
No announcement yet.
Cannot start bundle with hibernate. (ClassNotFoundException: MappingException) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot start bundle with hibernate. (ClassNotFoundException: MappingException)

    Hello,

    I am desperate here. I cannot get a hibernate based application to run under the dm server. During the application's startup process the DM Server reports a

    "ClassNotFoundException: org.hibernate.MappingException"

    which is very strang as I have installed the com.springsource.org.hibernate bundle (tried version 3.3.2.GA and 3.3.1.GA) which contains that class. The web console reports this bundle as started. I also have imported the package as well as the bundle as you can see from the manifest:

    Code:
    Manifest-Version: 1.0
    Export-Package: de.ypsilon.webshop.dao,de.ypsilon.webshop.domain
    Bundle-Version: 1.0.0
    Bundle-Name: Domain
    Bundle-ManifestVersion: 2
    Import-Bundle: com.springsource.org.hibernate;version="[3.3.1.GA,3.3.2.GA]"
    Import-Package: javax.persistence;version="[1.0.0,1.0.0]",
    de.ypsilon.generic;version="[1.0.0.0,1.0.0.0]",
    de.ypsilon.generic.spring.dao,
    org.springframework.beans;version="[3.0.0.RELEASE,3.0.0.RELEASE]",
    org.springframework.context;version="[3.0.0.RELEASE,3.0.0.RELEASE]",
    org.springframework.core;version="3.0.0.RELEASE",
    org.springframework.dao.support;version="[3.0.0.RELEASE,3.0.0.RELEASE]",
    org.springframework.orm.hibernate3;version="[3.0.0.RELEASE,3.0.0.RELEASE]",
    org.springframework.orm.hibernate3.annotation;version="[3.0.0.RELEASE,3.0.0.RELEASE]",
    org.springframework.orm.hibernate3.support;version="[3.0.0.RELEASE,3.0.0.RELEASE]",
    org.springframework.transaction.annotation;version="[3.0.0.RELEASE,3.0.0.RELEASE]"
    Bundle-SymbolicName: de.ypsilon.webshop.domain
    Is there anything I am missing here?

    Thanks in advance for any assistance.

    Greetings
    Peer

    PS: Here is the complete Stacktrace. Oh and the server is dm server 2.0.0.RELEASE running on linux with a jdk1.6 java (build 1.6.0_13-b03)

    Code:
    [2010-01-30 23:38:39.480] region-dm-14                 o.s.beans.factory.support.DefaultListableBeanFactory             DEBUG  Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor' 
    [2010-01-30 23:38:39.480] region-dm-14                 o.s.beans.factory.support.DefaultListableBeanFactory             DEBUG  Creating shared instance of singleton bean 'factory' 
    [2010-01-30 23:38:39.481] region-dm-14                 o.s.beans.factory.support.DefaultListableBeanFactory             DEBUG  Creating instance of bean 'factory' 
    [2010-01-30 23:38:39.482] region-dm-14                 o.s.beans.factory.support.DefaultListableBeanFactory             INFO  Destroying singletons in org.springframework.beans.factory.s
    upport.DefaultListableBeanFactory@b51c44: defining beans [org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,factory,transactionManager,itemDao,categoryDao,reviewDao,assetDao,messageDao,watchlistDao,org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean#0,org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean#1,org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean#2,org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean#3,org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean#4,org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean#5]; root of factory hierarchy 
    [2010-01-30 23:38:39.483] region-dm-14                 o.s.beans.factory.support.DefaultListableBeanFactory             DEBUG  Retrieved dependent beans for bean 'org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0': [org.springframework.transaction.config.internalTransactionAdvisor] 
    [2010-01-30 23:38:39.499] region-dm-14                 o.s.osgi.context.support.OsgiBundleXmlApplicationContext         DEBUG  Post refresh error org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'factory' defined in URL [bundleentry://73.fwk32858455/META-INF/spring/module-context.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/MappingException
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:946)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:890)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:540)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
            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 com.springsource.kernel.agent.dm.ContextPropagatingTaskExecutor$2.run(ContextPropagatingTaskExecutor.java:106)
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
            at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.NoClassDefFoundError: org/hibernate/MappingException
            at java.lang.Class.getDeclaredConstructors0(Native Method)
            at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
            at java.lang.Class.getConstructor0(Class.java:2699)
            at java.lang.Class.getDeclaredConstructor(Class.java:1985)
            at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:64)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:938)
            ... 18 common frames omitted
    Caused by: com.springsource.kernel.osgi.framework.ExtendedClassNotFoundException: org.hibernate.MappingException in KernelBundleClassLoader: [bundle=org.springframework.orm_3.0.0.RELEASE]
            at com.springsource.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:149)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
            ... 24 common frames omitted
    Caused by: java.lang.ClassNotFoundException: org.hibernate.MappingException
            at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:494)
            at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
            at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)
            at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
            at com.springsource.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:145)
            ... 26 common frames omitted

  • #2
    Some findings

    Hi,

    after doing some (actually a lot) more of try/error and MANIFEST.MF reading I came a bit closer to the solution.
    The ClassNotFound exception I mentioned above could be removed by doing the following:

    - put com.springsource.org.hibernate-3.3.2.GA.jar (and the required bundles) in the pickup directory
    - afterwards restart org.springframework.orm-3.0.0.RELEASE.jar

    The second step was done via the telnet/ssh console because I found no way of doing that with the web interface. However having done that the CNF Exception disappeard.

    Here is a question regarding that behaviour: In the MANIFEST of org.springframework.orm-3.0.0.RELEASE the packages org.hibernate are imported and marked as optional. That is the only link I can find between the two packages. If I want to use a bundle A which imports optionally foo.bar and I install a bundle B which exports foo.bar, is it always neccessary to restart A after installing B in order to use A and B in my Bundle?


    Unfortunatly the next problem appeard. This time the Entity annotation could not be found. Installing the hibernate.annotations bundle should solve this. Unfortunatly that refused to work too:
    Code:
    2010-01-31 18:26:55.880 .. HD0001I Hot deployer processing 'CREATED' event for file 'com.springsource.org.hibernate.annotations-3.4.0.GA.jar'. 
    2010-01-31 18:26:55.990 .. DE0000I Installing bundle 'com.springsource.org.hibernate.annotations' version '3.4.0.GA'. 
    2010-01-31 18:27:03.326 .. DE0002E Installation of bundle 'com.springsource.org.hibernate.annotations' version '3.4.0.GA' failed. com.springsource.kernel.osgi.framework.UnableToSatisfyBundleDependenciesException: Unable to satisfy dependencies of bundle 'com.springsource.org.hibernate.annotations' at version '3.4.0.GA': Cannot resolve: com.springsource.org.hibernate.annotations
        Resolver report:
            A Fragment-Host could not be resolved. The affected fragment is com.springsource.org.hibernate.annotations_3.4.0.GA
    Since neigther the com.springsource.org.hibernate.annotations-3.3.1.ga nor com.springsource.org.hibernate.annotations-3.4.0.GA would ever work, I finally decided to use the sledgehammer to crack that nut and copied the annotations directly to the hibernate bundle. After also adding the exported package org.hibernate.annotations with the (somewhat wrong version) "3.3.2.GA" to the MANIFES file, DM Server was able to find the Entity annotation.

    So far so good.
    But here is another question: Since I think my approach is a bit hacky (though I heard that the hibernate packages are somewhat bitchy), I'd like to know if there is any better way to resolve this?

    To bring this to an end (for anyone who is interested in it) here is my current problem, which is unsolved yet:

    Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.Reflec tionManager

    I have again no clue why this is the case as the package is exported.

    Probably that posting helps someone. Maybe anybody out there is able to answer my questions and would do me the favour of doing so.

    Thanks in advance and
    Greetings
    Peer

    Comment


    • #3
      Three tips may help.

      Firstly, ensure that any bundles you need which Spring has optional dependencies upon are placed in the repository chain (e.g. in repository/ext) before dm Server is started so that Spring gets wired to them. This is because if an optional import cannot be found when OSGi resolves a bundle, the bundle will remain without the import until the dependency is available and the bundle is refreshed.

      Secondly, if your application consists of more than one bundle, put them all in a scope (i.e. a PAR file or a scoped plan). This ensures the correct thread context class loading behaviour.

      It seems you are already using import-bundle to obtain hibernate types, but it is probably safe to use import-library to import the hibernate library into each application bundle, e.g:
      Code:
      Import-Library: org.hibernate.ejb;version="[3.4.0.GA,3.4.0.GA]"
      This is because it is next to impossible for an application to know the precise packages that hibernate requires the application to import and which hibernate bundles these packages come from. It is also sometimes difficult to predict which application bundles require access to hibernate types, which is why it is worth importing them into all the application bundles. (If you decide to stick with import-bundle, it is possible to "promote" these imports automatically to all the bundles in the application by adding the directive "import-scope:=application" to the import-bundle. Unfortunately, dm Server does not yet support this directive on import-library.)

      Comment


      • #4
        Hi,

        those three tips did indeed help. I just wanted to thank you for the assistance.
        Actually setting the Import-Library directive did the trick. Though not all bundles in that library could be started.


        (Unfortunatly I'm still facing problems starting the project, bundleContext is not set in some DAO. Actually I'm now very close to dropping the DM server as the risks seem uncalculatable for me, but we will see.).

        Greetings,
        Peer

        Comment


        • #5
          Sorry to hear this is proving so difficult. Let's hope there's just the one remaining problem to solve!

          It is possible to get hibernate to work with dm Server. Have you taken a look at the hibernate based Petclinic sample? Sometimes it is quicker to start from a working position and make incremental changes than to get in a hole and keep digging. Just a suggestion, possibly too late in your circumstances.

          Comment

          Working...
          X