Announcement Announcement Module
Collapse
No announcement yet.
Hibenate - OSGi - Problem with org.hibernate.cfg Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibenate - OSGi - Problem with org.hibernate.cfg

    Please, view the following posts.
    Last edited by TorTukiTu; Nov 17th, 2011, 08:30 AM.

  • #2
    Got same problem with SS bundles.

    Got the same error with SpringSource's hibernate bundles : (Currently working under Virgo web server (Equinox) )

    Code:
      [my_secret_app_name].dataSource: 0.0.1
      com.springsource.antlr: 2.7.7
      com.springsource.com.mchange.v2.c3p0: 0.9.1.2
      com.springsource.com.mysql.jdbc: 5.1.6
      com.springsource.javassist: 3.9.0.GA
      com.springsource.javax.sql.rowset: 1.0.1
      com.springsource.net.sf.cglib: 2.2.0
      com.springsource.org.apache.commons.collections: 3.2.0
      com.springsource.org.apache.commons.pool: 1.5.3
      com.springsource.org.dom4j: 1.6.1
      com.springsource.org.hibernate: 3.3.2.GA
      com.springsource.org.objectweb.asm: 1.5.3
      [my_secret_app_name].MyProfile.API: 0.1.0
      [my_secret_app_name].MyProfile.factory: 0.1.0
      [my_secret_app_name].MyProfile.lang: 0.0.1
      [my_secret_app_name].MyProfile.log: 0.0.1
      [my_secret_app_name].MyProfile.modele: 0.1.0
      [my_secret_app_name].MyProfile.provider: 2.4.0
      [my_secret_app_name].security: 2.4.0
      org.eclipse.virgo.apps.splash: 3.0.1.RELEASE
      org.springframework.security.acls: 3.0.0.RELEASE
      org.springframework.security.config: 3.0.0.RELEASE
      org.springframework.security.core: 3.0.0.RELEASE
      org.springframework.security.taglibs: 3.0.0.RELEASE
      org.springframework.security.web: 3.0.0.RELEASE
    Are resolved and started. I can see so

    Code:
    org.hibernate.cfg	3.3.2.GA	0	 x-equinox-ee:=-1
    uses:=org.dom4j, org.hibernate, org.hibernate.bytecode, org.hibernate.cache, org.hibernate.connection, org.hibernate.dialect, org.hibernate.dialect.function, org.hibernate.engine, org.hibernate.engine.query.sql, org.hibernate.event, org.hibernate.exception, org.hibernate.hql, org.hibernate.jdbc, org.hibernate.jdbc.util, org.hibernate.mapping, org.hibernate.proxy, org.hibernate.tool.hbm2ddl, org.hibernate.transaction, org.hibernate.tuple.entity, org.hibernate.type, org.w3c.dom, org.xml.sax
    x-internal:=false
    in com.springsource.org.hibernate: 3.3.2.GA. So the package exists.

    In my bundle-context I got:

    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    			<property name="dataSource" ref="dataSource"/>
    			<property name="mappingResources">
    				<list>
    					<value>/hibernate/MyProfile_document.xml</value>
    					<value>/hibernate/MyProfile_file.xml</value>
    					<value>/hibernate/MyProfile_group.xml</value>
    					<value>/hibernate/MyProfile_note.xml</value>
    					<value>/hibernate/MyProfile_user.xml</value>
    					<value>/hibernate/MyProfile_friend.xml</value>
    				</list>
    			</property>
    			<property name="hibernateProperties">
    				<props>
    				<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    				</props>
    			</property> 
    	   </bean>
    And in my MANIFEST.MF, I got

    Code:
    Manifest-Version: 1.0
    Private-Package: .... Many Packages ....
    Built-By: Georges
    Tool: Bnd-0.0.238
    Bundle-Name: Spring OSGi Bundle
    Created-By: Apache Maven Bundle Plugin
    Import-Bundle: com.springsource.org.hibernate
    Bundle-Version: 0.1
    Build-Jdk: 1.6.0_22
    Bnd-LastModified: 1321525831524
    Bundle-ManifestVersion: 2
    Import-Package: com.mysql.jdbc,[my_secret_app_name].modele.beans
     .documents,[my_secret_app_name].modele.beans.users,[my_secret_app_name].services.consumer.contract,[my_secret_app_name].
     services.modele.contract,javax.sql,org.hibernate;version="3.3.2.GA",o
     rg.hibernate.cfg;version="3.3.2.GA",org.hibernate.classic;version="3.
     3.2.GA",org.hibernate.criterion;version="3.3.2.GA",org.hibernate.dial
     ect;version="3.3.2.GA",org.springframework.beans;version="2.5",org.sp
     ringframework.context;version="2.5",org.springframework.jdbc.datasour
     ce,org.springframework.orm.hibernate3
    Bundle-SymbolicName: [my_secret_app_name].MyProfile.consumer
    With the dataSource as a service (following Spring-DM good practices):

    Code:
    <osgi:reference id="dataSource" interface="javax.sql.DataSource"></osgi:reference>
    And in the datasource bundle :

    Code:
            <bean
    		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="locations">
    			<value>classpath:META-INF/spring/database.properties</value>
    		</property>
    	</bean>
    
    	<!-- Database Properties -->
    	
    	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    		<property name="driverClass" value="${driver.classname}"></property>
    		<property name="jdbcUrl" value="${database.url}"></property>
    		<property name="user" value="${database.username}"></property>
    		<property name="password" value="${database.password}"></property>
    	</bean>
           <!-- Data Source service -->
           <osgi:service id="dataSourceService" ref="dataSource" interface="javax.sql.DataSource"/>
    I Also added <Import-Bundle>com.springsource.com.mysql.jdbc</Import-Bundle> to the com.springsource.com.mchange.v2.c3p0 library. (Using c3p0 instead of the SessionManager and it's annoying class.forName() )

    I don't understand what I have done wrong....

    When I run my bundle, got the following error:

    Code:
    [2011-11-17 14:19:21.417] start-signalling-4           <DE0006E> Start failed for bundle '[my_secret_app_name].consumer' version '0.1.0'. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [bundleentry://148.fwk4098499/META-INF/spring/bundle-context.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:965)
      ....
    
    [2011-11-17 14:30:50.932] region-dm-7                  <AG0000E> Application context creation failure for bundle '[my_secret_app_name].MyProfile.consumer' version '0.1.0'. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [bundleentry://149.fwk4098499/META-INF/spring/bundle-context.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:965)
            at ...
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)
            ... 18 common frames omitted
    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:39)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
            at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
            ... 20 common frames omitted
    
    [2011-11-17 14:30:50.937] start-signalling-4           <DE0006E> Start failed for bundle '[my_secret_app_name].MyProfile.consumer' version '0.1.0'. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [bundleentry://149.fwk4098499/META-INF/spring/bundle-context.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:965)
    ....
    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)
    ...
            ... 18 common frames omitted
    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)
     ...
            ... 20 common frames omitted
    Why is org/hibernate/cfg/Configuration not found ???

    Any help will be greatly apreciated !

    Thank you !
    Last edited by TorTukiTu; Nov 17th, 2011, 06:47 AM.

    Comment


    • #3
      Have you tried to import the package org.hibernate.cfg in your bundle (or the bundle that throws the exception)?

      When you are not using an autogenerated MANIFEST.MF I would recommend this, it is very convenient and will save
      you a lot of problems. Have a look at bnd / bndtools / maven-bundle-plugin / bundlor for this.

      http://www.aqute.biz/Bnd/Bnd
      http://bndtools.org/
      http://www.springsource.org/bundlor
      http://felix.apache.org/site/apache-...lugin-bnd.html

      Comment


      • #4
        Got a more precise error message:

        Code:
        Caused by: org.eclipse.virgo.kernel.osgi.framework.ExtendedClassNotFoundException: org.hibernate.cfg.Configuration in KernelBundleClassLoader: [bundle=org.springframework.orm_3.0.5.RELEASE]
                at org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:138)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
                ... 26 common frames omitted
        Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
                at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
                at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
                at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
                at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
                at org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:134)
                ... 27 common frames omitted

        May it be because teh bundle containing org.springframework.orm.hibernate3.LocalSessionFac toryBean in /repo/ext of Virgo ( = org.springframework.orm-3.0.5.RELEASE ) is not importing org.hibernate.cfg ?

        If it's the case, I am a bit lost =/ I don't know how to solve the problem... (Modifing a MANIFEST of a bundle in /repository/ext is too ugly)
        Last edited by TorTukiTu; Nov 17th, 2011, 08:23 AM.

        Comment


        • #5
          Hey,

          the bundle that cannot load the package org.hibernate.cfg is org.springframework.orm_3.0.5.RELEASE. This might be because of a problem in that bundle (which I doubt) or because the package org.hibernate.cfg is never exported (or not with the correct version at least).

          http://www.eclipse.org/virgo/documen...html/ch07.html

          Maybe have a look in the virgo OSGi management interface whether
          - the hibernate bundle is installed and active/started
          - the hibernate bundle exports the package org.hibernate.cfg (check the version)
          - the org.springframework.orm bundle imports the same version

          and check the log files for classloading exceptions.

          Regards,
          Leen

          Comment


          • #6
            Thank you for answering, I posted the same thread on Virgo forum,

            Here are the answers:

            Hi,

            Have you checked Virgo's documentation. We have a section that covers working with Hibernate that gives a hint to add hibernate to your application's scope so that even bundles in it without reference to hibernate can load it.
            http://www.eclipse.org/virgo/documen...ries-hibernate

            HTH,
            Borislav
            Thank you for answering, Borislav Kapukaranov.

            I already read it.

            The problem seems to be one of the /reposiroty/ext (org.springframework.orm.hibernate3.LocalSessionFa ctoryBean) does not to import the org.hibernate.cfg package (But it currently do ! => see http://www.eclipse.org/forums/index....78/#msg_757378)

            Code:
            Caused by: org.eclipse.virgo.kernel.osgi.framework.ExtendedClassNotFoundException: org.hibernate.cfg.Configuration in KernelBundleClassLoader: [bundle=org.springframework.orm_3.0.5.RELEASE]
            I can't make a par file with /ext bundles. So the import-scope:=application instruction will be useless in that case.

            An other strange thing, sometimes I don't got the upper line, but the exception "stops" at :

            Code:
            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:39)
                    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
                    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
                    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
                    ... 20 common frames omitted
            Is this exception really caused by the org.springframework.orm which try to use hibernate ?

            An other guy answered me on the Spring forum :

            [quote title=Quote:]
            Maybe have a look in the virgo OSGi management interface whether
            - the hibernate bundle is installed and active/started
            - the hibernate bundle exports the package org.hibernate.cfg (check the version)
            - the org.springframework.orm bundle imports the same version
            [/quote]

            - the hibernate bundle is installed and active/started => Yes
            [com.springsource.org.hibernate: 3.3.2.GA => ACTIVE ]
            - the hibernate bundle exports the package org.hibernate.cfg (check the version) => Yes
            [org.hibernate.cfg 3.3.2.GA => Importing in my MANIFEST.MF org.hibernate.cfg without version specification]
            - the org.springframework.orm bundle imports the same version => Yes
            [org.hibernate.cfg; version="[3.2.0,4.0.0)"<unwired><optional>]

            According to the class documentation at http://static.springsource.org/sprin...toryBean.html,

            org.springframework.orm.hibernate3.AbstractSession FactoryBean Has the following method :

            Code:
            protected  SessionFactory 	newSessionFactory(Configuration config)
            With Configuration = org.hibernate.cfg.Configuration

            I suppose I did something wrong and the wrong classloader is used for some reason...

            A little hint please ?

            Thank you ! =)
            Last edited by TorTukiTu; Nov 18th, 2011, 12:45 AM.

            Comment

            Working...
            X