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

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


    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 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:

    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-Package: javax.persistence;version="[1.0.0,1.0.0]",
    Bundle-SymbolicName: de.ypsilon.webshop.domain
    Is there anything I am missing here?

    Thanks in advance for any assistance.


    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)

    [2010-01-30 23:38:39.480] region-dm-14                    DEBUG  Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor' 
    [2010-01-30 23:38:39.480] region-dm-14                    DEBUG  Creating shared instance of singleton bean 'factory' 
    [2010-01-30 23:38:39.481] region-dm-14                    DEBUG  Creating instance of bean 'factory' 
    [2010-01-30 23:38:39.482] region-dm-14                    INFO  Destroying singletons in org.springframework.beans.factory.s
    [email protected]: 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,,,,,,]; root of factory hierarchy 
    [2010-01-30 23:38:39.483] region-dm-14                    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                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.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(
            at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$
            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
            at java.util.concurrent.ThreadPoolExecutor$
    Caused by: java.lang.NoClassDefFoundError: org/hibernate/MappingException
            at java.lang.Class.getDeclaredConstructors0(Native Method)
            at java.lang.Class.privateGetDeclaredConstructors(
            at java.lang.Class.getConstructor0(
            at java.lang.Class.getDeclaredConstructor(
            ... 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(
            at java.lang.ClassLoader.loadClass(
            at java.lang.ClassLoader.loadClassInternal(
            ... 24 common frames omitted
    Caused by: java.lang.ClassNotFoundException: org.hibernate.MappingException
            at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(
            at org.eclipse.osgi.internal.loader.BundleLoader.findClass(
            at org.eclipse.osgi.internal.loader.BundleLoader.findClass(
            at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(
            at com.springsource.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(
            ... 26 common frames omitted

  • #2
    Some findings


    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 (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 and I install a bundle B which exports, 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:
    2010-01-31 18:26:55.880 .. HD0001I Hot deployer processing 'CREATED' event for file ''. 
    2010-01-31 18:26:55.990 .. DE0000I Installing bundle '' version '3.4.0.GA'. 
    2010-01-31 18:27:03.326 .. DE0002E Installation of bundle '' version '3.4.0.GA' failed. com.springsource.kernel.osgi.framework.UnableToSatisfyBundleDependenciesException: Unable to satisfy dependencies of bundle '' at version '3.4.0.GA': Cannot resolve:
        Resolver report:
            A Fragment-Host could not be resolved. The affected fragment is
    Since neigther the nor 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


    • #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:
      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.)


      • #4

        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.).



        • #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.