5 Replies Latest reply on Jun 6, 2017 2:31 AM by grgrzybek

    Camel-Hibernate Issue with Blueprint

    sarada.ch

      Hi All,

      When using camel-hibernate component with Spring DSL it works fine but I want to use Blueprint with JBoss fuse 6.3 I get error

       

      org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: sessionFactory, getter: class org.apacheextras.camel.component.hibernate.HibernateComponent.getSessionFactory(), setter: [class org.apacheextras.camel.component.hibernate.HibernateComponent.setSessionFactory(interface org.hibernate.SessionFactory)]

          at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:939)

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

          at java.lang.Thread.run(Thread.java:745)

      Caused by: java.lang.Exception: Unable to convert value org.springframework.orm.hibernate4.LocalSessionFactoryBean@46797063 to type org.hibernate.SessionFactory

          at org.apache.aries.blueprint.container.AggregateConverter.convert(AggregateConverter.java:184)

       

       

      for more please find at

      Camel-Blueprint Unable to convert value org.springframework.orm.hibernate4.LocalSessionFactoryBean to type org.hibernate…

        • 1. Re: Camel-Hibernate Issue with Blueprint
          grgrzybek

          Hello

           

          Answered on SO, but also here for completeness:

           

          Remember one thing. `org.springframework.orm.hibernate4.LocalSessionFactoryBean` is Spring's _factory bean_ which, when used as `<bean>` gives you a kind of indirection - instead of using the class as bean directly, `getObject()` is called and the returned object is your `<bean>`.

           

          Another thing is that Spring automatically calls `afterPropertiesSet()` for all beans (or factory beans) that implement `InitializingBean`.

           

          So instead of:

           

              <bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"

                      id="mysessionFactory">

           

          use:

           

              <bean id="mysessionFactory" factory-ref="mysessionFactoryFactory"

                    factory-method="getObject" init-method="afterPropertiesSet" />

           

              <bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"

                      id="mysessionFactoryFactory">

              ...

           

          regards
          Grzegorz Grzybek

          • 2. Re: Camel-Hibernate Issue with Blueprint
            sarada.ch

            Hi Grzegorz,

             

            I ran into different exception after the above changes:

             

            org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to instantiate components

                at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:686)

                at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:377)

            Caused by: java.lang.NullPointerException

                at org.apache.aries.blueprint.container.BeanRecipe.getInitMethod(BeanRecipe.java:619)

             

            Many Thanks,

            Sarada

            • 3. Re: Camel-Hibernate Issue with Blueprint
              grgrzybek

              I'm sorry - I wrote from top of my head without running the example - `afterPropertiesSet` is a method of LocalSessionFactoryBean, so add init-method="afterPropertiesSet" on:

               

                <bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"

                          id="mysessionFactoryFactory" init-method="afterPropertiesSet">

               

              regards

              Grzegorz Grzybek

              • 4. Re: Camel-Hibernate Issue with Blueprint
                sarada.ch

                Thanks a lot for valuable input.

                 

                It worked amazing.

                 

                It would be great if camel developers can update the same in the camel-hibernate example for blueprint Apache Camel: Hibernate Example

                • 5. Re: Camel-Hibernate Issue with Blueprint
                  grgrzybek

                  I'm glad it worked

                   

                  About updating camel example - you can always send PR to https://github.com/camel-extra/camel-extra/tree/master/examples/camel-example-hibernate.

                   

                  regards

                  Grzegorz Grzybek