You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Pratt, Jason" <Ja...@windriver.com> on 2015/11/06 02:37:24 UTC

jpa/hibernate casting exception

Hello - I am running into an error that has me shaking my head. I've setup a consuming JPA route with the following blueprint. I am getting the exception at the bottom which is preventing me from moving further. I am using JPA/Hibernate in KARAF 3.0.4
Any help would be great!

Jason


from("jpa://test.ProductBean?consumer.delay=14400s&consumer.namedQuery=Product.findAllActiveOrderByExternalName").routeId("testRoute")

<camelContext xmlns=http://camel.apache.org/schema/blueprint id="TestReports">
<routeBuilder ref="testReportRoute" />
</camelContext>

<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
      <jpa:context property="em" unitname="test" />
      <tx:transaction method="*" value="Required" />
</bean>


2015-11-05 17:23:15,570 | INFO  | raf-3.0.4/deploy | BlueprintCamelContext            | 255 - org.apache.camel.camel-core - 2.15.2 | Apache Camel 2.15.2 (CamelContext: TestReports) is shutting down
2015-11-05 17:23:15,571 | INFO  | raf-3.0.4/deploy | BlueprintCamelContext            | 255 - org.apache.camel.camel-core - 2.15.2 | Apache Camel 2.15.2 (CamelContext: TestReports) uptime not started
2015-11-05 17:23:15,571 | INFO  | raf-3.0.4/deploy | BlueprintCamelContext            | 255 - org.apache.camel.camel-core - 2.15.2 | Apache Camel 2.15.2 (CamelContext: TestReports) is shutdown in 0.001 seconds
2015-11-05 17:23:15,571 | ERROR | raf-3.0.4/deploy | BlueprintContainerImpl           | 15 - org.apache.aries.blueprint.core - 1.4.3 | Unable to start blueprint container for bundle test
org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: entityManagerFactory, getter: class org.apache.camel.component.jpa.JpaComponent.getEntityManagerFactory(), setter: [class org.apache.camel.component.jpa.JpaComponent.setEntityManagerFactory(interface javax.persistence.EntityManagerFactory)]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:941)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:907)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:888)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:820)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[15:org.apache.aries.blueprint.core:1.4.3]
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)[:1.7.0_79]
        at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:682)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:377)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:294)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:263)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:253)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[9:org.apache.aries.util:1.1.0]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[9:org.apache.aries.util:1.1.0]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[9:org.apache.aries.util:1.1.0]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[9:org.apache.aries.util:1.1.0]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[9:org.apache.aries.util:1.1.0]
        at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1103)[org.apache.felix.framework-4.2.1.jar:]
        at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:695)[org.apache.felix.framework-4.2.1.jar:]
        at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:483)[org.apache.felix.framework-4.2.1.jar:]
        at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4403)[org.apache.felix.framework-4.2.1.jar:]
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2092)[org.apache.felix.framework-4.2.1.jar:]
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1.jar:]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1245)[7:org.apache.felix.fileinstall:3.5.0]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1217)[7:org.apache.felix.fileinstall:3.5.0]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:509)[7:org.apache.felix.fileinstall:3.5.0]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)[7:org.apache.felix.fileinstall:3.5.0]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)[7:org.apache.felix.fileinstall:3.5.0]
Caused by: java.lang.Exception: Unable to convert value org.hibernate.jpa.internal.EntityManagerImpl@7413ef9 to type javax.persistence.EntityManagerFactory
        at org.apache.aries.blueprint.container.AggregateConverter.convert(AggregateConverter.java:184)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BlueprintRepository.convert(BlueprintRepository.java:402)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.convert(ReflectionUtils.java:394)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.utils.ReflectionUtils$MethodPropertyDescriptor.internalSet(ReflectionUtils.java:628)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.set(ReflectionUtils.java:378)[15:org.apache.aries.blueprint.core:1.4.3]
        at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:939)[15:org.apache.aries.blueprint.core:1.4.3]
        ... 31 more

Re: jpa/hibernate casting exception

Posted by Claus Ibsen <cl...@gmail.com>.
Yeah sadly OSGi can be a pain with classloading and setting up JPA.

There is some 3rd party blogs from ppl that explains how to do this.
Try to search the internet to find those.

On Fri, Nov 6, 2015 at 2:37 AM, Pratt, Jason <Ja...@windriver.com> wrote:
> Hello - I am running into an error that has me shaking my head. I've setup a consuming JPA route with the following blueprint. I am getting the exception at the bottom which is preventing me from moving further. I am using JPA/Hibernate in KARAF 3.0.4
> Any help would be great!
>
> Jason
>
>
> from("jpa://test.ProductBean?consumer.delay=14400s&consumer.namedQuery=Product.findAllActiveOrderByExternalName").routeId("testRoute")
>
> <camelContext xmlns=http://camel.apache.org/schema/blueprint id="TestReports">
> <routeBuilder ref="testReportRoute" />
> </camelContext>
>
> <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>       <jpa:context property="em" unitname="test" />
>       <tx:transaction method="*" value="Required" />
> </bean>
>
>
> 2015-11-05 17:23:15,570 | INFO  | raf-3.0.4/deploy | BlueprintCamelContext            | 255 - org.apache.camel.camel-core - 2.15.2 | Apache Camel 2.15.2 (CamelContext: TestReports) is shutting down
> 2015-11-05 17:23:15,571 | INFO  | raf-3.0.4/deploy | BlueprintCamelContext            | 255 - org.apache.camel.camel-core - 2.15.2 | Apache Camel 2.15.2 (CamelContext: TestReports) uptime not started
> 2015-11-05 17:23:15,571 | INFO  | raf-3.0.4/deploy | BlueprintCamelContext            | 255 - org.apache.camel.camel-core - 2.15.2 | Apache Camel 2.15.2 (CamelContext: TestReports) is shutdown in 0.001 seconds
> 2015-11-05 17:23:15,571 | ERROR | raf-3.0.4/deploy | BlueprintContainerImpl           | 15 - org.apache.aries.blueprint.core - 1.4.3 | Unable to start blueprint container for bundle test
> org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: entityManagerFactory, getter: class org.apache.camel.component.jpa.JpaComponent.getEntityManagerFactory(), setter: [class org.apache.camel.component.jpa.JpaComponent.setEntityManagerFactory(interface javax.persistence.EntityManagerFactory)]
>         at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:941)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:907)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:888)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:820)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[15:org.apache.aries.blueprint.core:1.4.3]
>         at java.util.concurrent.FutureTask.run(FutureTask.java:262)[:1.7.0_79]
>         at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:682)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:377)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:294)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:263)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:253)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[9:org.apache.aries.util:1.1.0]
>         at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[9:org.apache.aries.util:1.1.0]
>         at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[9:org.apache.aries.util:1.1.0]
>         at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[9:org.apache.aries.util:1.1.0]
>         at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[9:org.apache.aries.util:1.1.0]
>         at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1103)[org.apache.felix.framework-4.2.1.jar:]
>         at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:695)[org.apache.felix.framework-4.2.1.jar:]
>         at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:483)[org.apache.felix.framework-4.2.1.jar:]
>         at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4403)[org.apache.felix.framework-4.2.1.jar:]
>         at org.apache.felix.framework.Felix.startBundle(Felix.java:2092)[org.apache.felix.framework-4.2.1.jar:]
>         at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1.jar:]
>         at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1245)[7:org.apache.felix.fileinstall:3.5.0]
>         at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1217)[7:org.apache.felix.fileinstall:3.5.0]
>         at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:509)[7:org.apache.felix.fileinstall:3.5.0]
>         at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)[7:org.apache.felix.fileinstall:3.5.0]
>         at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)[7:org.apache.felix.fileinstall:3.5.0]
> Caused by: java.lang.Exception: Unable to convert value org.hibernate.jpa.internal.EntityManagerImpl@7413ef9 to type javax.persistence.EntityManagerFactory
>         at org.apache.aries.blueprint.container.AggregateConverter.convert(AggregateConverter.java:184)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BlueprintRepository.convert(BlueprintRepository.java:402)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.convert(ReflectionUtils.java:394)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.utils.ReflectionUtils$MethodPropertyDescriptor.internalSet(ReflectionUtils.java:628)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.set(ReflectionUtils.java:378)[15:org.apache.aries.blueprint.core:1.4.3]
>         at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:939)[15:org.apache.aries.blueprint.core:1.4.3]
>         ... 31 more



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: jpa/hibernate casting exception

Posted by Christian Schneider <ch...@die-schneider.net>.
As EntityManagerImpl of course implements EntityManagerFactory the 
exception means that there are two different bundles that provide the 
package javax.persistence in your framework. Hibernate binds to one of 
the bundles and camel to the other. As in java classes are only the same 
if they are loaded by the same classloader there is this exception.

The best solution is to make sure there is only one bundle that exports 
the package javax.persistence.
In your case I am pretty sure that the problem is that you have 
javax.persistence 2.0.0 and 2.1.0 deployed at the same time.

I just tried to reproduce by installing:

feature:repo-add camel 2.15.2
camel-jpa hibernate

This install hibernate 4.3.6.

Unfortunately the hibernate feature installs javax.persistence / 2.1.0 
and camel-jpa install javax.persistence / 2.0.0.

So there are a few options to solve this:
1. You could patch the camel feature file to install the 2.1.0 version 
of the api (ugly but not that difficult)
2. You could install hibernate 4.2.x which will install jpa 2.0.0 (you 
will loose jpa 2.1.0 support)
3. You could update to karaf 4 which has a better feature resolver that 
can handle this case gracefully. In karaf 4 the flag dependency=true on 
bundles is honored and will make sure that only one version of a package 
is installed if possible.

If you switch to karaf 4 then you should wait for version 4.0.3 (to be 
release this week) as 4.0.2 has a severe bug in Aries blueprint that 
makes Aries JPA fail after 5 minutes.

Christian

On 06.11.2015 02:37, Pratt, Jason wrote:
> Hello - I am running into an error that has me shaking my head. I've setup a consuming JPA route with the following blueprint. I am getting the exception at the bottom which is preventing me from moving further. I am using JPA/Hibernate in KARAF 3.0.4
> Any help would be great!
>
> Jason
>
>
> from("jpa://test.ProductBean?consumer.delay=14400s&consumer.namedQuery=Product.findAllActiveOrderByExternalName").routeId("testRoute")
>
> <camelContext xmlns=http://camel.apache.org/schema/blueprint id="TestReports">
> <routeBuilder ref="testReportRoute" />
> </camelContext>
>
> <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
>        <jpa:context property="em" unitname="test" />
>        <tx:transaction method="*" value="Required" />
> </bean>
>
>
>
> Caused by: java.lang.Exception: Unable to convert value org.hibernate.jpa.internal.EntityManagerImpl@7413ef9 to type javax.persistence.EntityManagerFactory
>          at org.apache.aries.blueprint.container.AggregateConverter.convert(AggregateConverter.java:184)[15:org.apache.aries.blueprint.core:1.4.3]
>          at org.apache.aries.blueprint.container.BlueprintRepository.convert(BlueprintRepository.java:402)[15:org.apache.aries.blueprint.core:1.4.3]
>          at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.convert(ReflectionUtils.java:394)[15:org.apache.aries.blueprint.core:1.4.3]
>          at org.apache.aries.blueprint.utils.ReflectionUtils$MethodPropertyDescriptor.internalSet(ReflectionUtils.java:628)[15:org.apache.aries.blueprint.core:1.4.3]
>          at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.set(ReflectionUtils.java:378)[15:org.apache.aries.blueprint.core:1.4.3]
>          at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:939)[15:org.apache.aries.blueprint.core:1.4.3]
>          ... 31 more
>


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com