I like the CDI way of doing DI, so I decided to dump the JPA  Camel component.

Ended up using beanRef invoking CDI Bean with injected EntityManager (for 
RESOURCE_LOCAL datas source). Had to begin/commit transaction manually) and it 
works.

It would be nice if Deltaspike JPA module ca help here (@Transactional doesn't 
seem to be doing anything), but it's manageable so far.


Cheers,

Dmitry

________________________________
From: Romain Manni-Bucau <[email protected]>
Sent: 05 August 2016 23:53:16
To: [email protected]
Subject: RE: Camel JPA + JTA Transaction (TomEE)

Le 6 août 2016 02:22, "Shultz, Dmitry" <[email protected]> a écrit :
>
> Can't set the org.apache.camel.cdi.CdiCamelExtension.active=false in
conf/system.properties because there will be other apps deployed on the
same TomEE and they have no problems  (because they don't use any Camel
JPA).
> Also can't override the afterDeploymentValidation() because it is
private, in fact all the methods in org.apache.camel.cdi.CdiCamelExtension
class are private except of default Constructor - very well encapsulated...
may be a bit too well.
>

WEB-INF/application.properties can hold it within the app too

> While I'm working on the github project to reproduce the issue, I need to
deploy something working into our environment (i.e. something that can be
restarted), so I decided to try not to use RESOURCE_LOCAL instead of JTA
data source. It fails on :
>
> 17:15| ERROR | CamelLogger.java 156 |
javax.persistence.TransactionRequiredException: no transaction is in
progress
>         at
org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:993)
>         at
org.apache.camel.component.jpa.JpaProducer$1.doInTransaction(JpaProducer.java:99)
>         at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
>         at
org.apache.camel.component.jpa.JpaProducer.process(JpaProducer.java:62)
>         at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
>         at
org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
>
> How do I create transaction manually for JPA Camel?
>
>

Think you have to rely on spring.

That said a workaround for your app would be to use reflection - or add
openejb-core as provided in your pom - and get the txmgr doing
OpenEJB.getTransactionManager().

>
> -----Original Message-----
> From: Romain Manni-Bucau [mailto:[email protected]]
> Sent: August-05-16 1:57 PM
> To: [email protected]
> Subject: RE: Camel JPA + JTA Transaction (TomEE)
>
> org.apache.camel.cdi.CdiCamelExtension.active=false in
conf/system.properties then redefine this extension - likely extend camel
one to override afterDeploymentValidation and dont forget to register it
through standard SPI file.
>
> Thinking to it using a servletcontextlistener if in a servlet container
can be a better way to init camel - can be done automatically and switch
back to either cdi or something else if in standalone.
>
> Le 5 août 2016 21:58, "Shultz, Dmitry" <[email protected]> a
écrit :
>
> It looks like
org.apache.camel.cdi.CdiCamelExtension.afterDeploymentValidation()
> kicks up the Camel validation befiore TomEE is fully initialized. If
there any way to disable this (or call validation manually later)?
>
> -----Original Message-----
> From: Antonin Stefanutti [mailto:[email protected]]
> Sent: August-05-16 11:48 AM
> To: [email protected]
> Subject: Re: Camel JPA + JTA Transaction (TomEE)
>
> Note that Camel CDI does not change the semantic of
context.setAutoStartup(false), that is the routes within the context are
not started, though the context itself is started so that validation can
occur when the application initialise.
>
> > On 05 Aug 2016, at 20:08, Romain Manni-Bucau <[email protected]>
> wrote:
> >
> > try sharing a sample with this issue on github with tomee-maven-plugin
> > setup to reproduce it (mvn package tomee:run -> fails). Would be more
> > relevant than guessing the actual issue.
> >
> >
> > Romain Manni-Bucau
> > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > <http://rmannibucau.wordpress.com> | Github
> > <https://github.com/rmannibucau> | LinkedIn
> > <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > <http://www.tomitribe.com> | JavaEE Factory
> > <https://javaeefactory-rmannibucau.rhcloud.com>
> >
> > 2016-08-05 20:06 GMT+02:00 dimas <[email protected]>:
> >
> >> Tried that, doesn't work. CDI is starting CamelContext even with
> >> context.setAutoStartup(false).
> >>
> >> SEVERE - Failed to create Producer for endpoint:
> >> Endpoint[jpa://com.kaltire.mix.wosess.model.ScanEvent]. Reason:
> >> javax.persistence.PersistenceException: No persistence providers
> >> available for "camel" after trying the following discovered
> implementations:
> >> org.apache.openjpa.persistence.PersistenceProviderImpl,
> >> org.hibernate.ejb.HibernatePersistence
> >> org.apache.camel.FailedToCreateProducerException: Failed to create
> >> Producer for endpoint:
> >> Endpoint[jpa://com.kaltire.mix.wosess.model.ScanEvent].
> >> Reason: javax.persistence.PersistenceException: No persistence
> >> providers available for "camel" after trying the following discovered
> >> implementations:
> >> org.apache.openjpa.persistence.PersistenceProviderImpl,
> >> org.hibernate.ejb.HibernatePersistence
> >>        at
> >>
org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:444)
> >>        at
> >> org.apache.camel.impl.ProducerCache.acquireProducer(
> >> ProducerCache.java:160)
> >>        at org.apache.camel.processor.SendProcessor.doStart(
> >> SendProcessor.java:243)
> >>        at org.apache.camel.support.ServiceSupport.start(
> >> ServiceSupport.java:61)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:75)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:60)
> >>        at
> >>
org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:104)
> >>        at org.apache.camel.util.ServiceHelper.startServices(
> >> ServiceHelper.java:90)
> >>        at
> >> org.apache.camel.processor.DelegateAsyncProcessor.doStart(
> >> DelegateAsyncProcessor.java:79)
> >>        at org.apache.camel.support.ServiceSupport.start(
> >> ServiceSupport.java:61)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:75)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:60)
> >>        at
> >>
org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:104)
> >>        at org.apache.camel.util.ServiceHelper.startServices(
> >> ServiceHelper.java:90)
> >>        at
> >> org.apache.camel.processor.RedeliveryErrorHandler.doStart(
> >> RedeliveryErrorHandler.java:1372)
> >>        at
> >> org.apache.camel.support.ChildServiceSupport.start(
> >> ChildServiceSupport.java:44)
> >>        at
> >> org.apache.camel.support.ChildServiceSupport.start(
> >> ChildServiceSupport.java:31)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:75)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:60)
> >>        at
> >>
org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:104)
> >>        at org.apache.camel.util.ServiceHelper.startServices(
> >> ServiceHelper.java:90)
> >>        at
> >> org.apache.camel.processor.interceptor.DefaultChannel.
> >> doStart(DefaultChannel.java:156)
> >>        at org.apache.camel.support.ServiceSupport.start(
> >> ServiceSupport.java:61)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:75)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:60)
> >>        at
> >>
org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:104)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:62)
> >>        at
> >>
org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:104)
> >>        at org.apache.camel.util.ServiceHelper.startServices(
> >> ServiceHelper.java:90)
> >>        at
> >> org.apache.camel.processor.MulticastProcessor.doStart(
> >> MulticastProcessor.java:1149)
> >>        at org.apache.camel.support.ServiceSupport.start(
> >> ServiceSupport.java:61)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:75)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:60)
> >>        at
> >>
org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:104)
> >>        at org.apache.camel.util.ServiceHelper.startServices(
> >> ServiceHelper.java:90)
> >>        at
> >> org.apache.camel.processor.DelegateAsyncProcessor.doStart(
> >> DelegateAsyncProcessor.java:79)
> >>        at org.apache.camel.support.ServiceSupport.start(
> >> ServiceSupport.java:61)
> >>        at org.apache.camel.util.ServiceHelper.startService(
> >> ServiceHelper.java:75)
> >>        at
> >> org.apache.camel.impl.RouteService.startChildService(
> >> RouteService.java:340)
> >>        at org.apache.camel.impl.RouteService.warmUp(
> >> RouteService.java:182)
> >>        at
> >> org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(
> >> DefaultCamelContext.java:3496)
> >>        at
> >> org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(
> >> DefaultCamelContext.java:3426)
> >>        at
> >> org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(
> >> DefaultCamelContext.java:3203)
> >>        at
> >> org.apache.camel.impl.DefaultCamelContext.doStartCamel(
> >> DefaultCamelContext.java:3059)
> >>        at
> >> org.apache.camel.impl.DefaultCamelContext.access$
> >> 000(DefaultCamelContext.java:175)
> >>        at
> >> org.apache.camel.impl.DefaultCamelContext$2.call(
> >> DefaultCamelContext.java:2854)
> >>        at
> >> org.apache.camel.impl.DefaultCamelContext$2.call(
> >> DefaultCamelContext.java:2850)
> >>        at
> >> org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(
> >> DefaultCamelContext.java:2873)
> >>        at
> >> org.apache.camel.impl.DefaultCamelContext.doStart(
> >> DefaultCamelContext.java:2850)
> >>        at org.apache.camel.support.ServiceSupport.start(
> >> ServiceSupport.java:61)
> >>        at
> >> org.apache.camel.impl.DefaultCamelContext.start(
> >> DefaultCamelContext.java:2819)
> >>        at
> >> org.apache.camel.CamelContext$$OwbNormalScopeProxy0.start(
> >> org/apache/camel/CamelContext.java)
> >>        at
> >> org.apache.camel.cdi.CdiCamelExtension.afterDeploymentValidation(
> >> CdiCamelExtension.java:376)
> >>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >>        at
> >> sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.java:
> >> 62)
> >>        at
> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(
> >> DelegatingMethodAccessorImpl.java:43)
> >>        at java.lang.reflect.Method.invoke(Method.java:497)
> >>        at
> >> org.apache.webbeans.event.ObserverMethodImpl.invoke(
> >> ObserverMethodImpl.java:347)
> >>        at
> >> org.apache.webbeans.event.ContainerEventObserverMethodImpl.invoke(
> >> ContainerEventObserverMethodImpl.java:82)
> >>        at
> >> org.apache.webbeans.event.ObserverMethodImpl.notify(
> >> ObserverMethodImpl.java:312)
> >>        at
> >> org.apache.webbeans.event.NotificationManager.fireEvent(
> >> NotificationManager.java:676)
> >>        at
> >> org.apache.webbeans.container.BeanManagerImpl.fireEvent(
> >> BeanManagerImpl.java:485)
> >>        at
> >> org.apache.webbeans.container.BeanManagerImpl.fireLifecycleEvent(
> >> BeanManagerImpl.java:480)
> >>        at
> >> org.apache.webbeans.config.BeansDeployer.fireAfterDeploymentValidatio
> >> nE
> >> vent(BeansDeployer.java:719)
> >>        at org.apache.webbeans.config.BeansDeployer.deploy(
> >> BeansDeployer.java:314)
> >>        at
> >> org.apache.openejb.cdi.OpenEJBLifecycle.startApplication(
> >> OpenEJBLifecycle.java:196)
> >>        at
> >> org.apache.openejb.cdi.ThreadSingletonServiceImpl.initialize(
> >> ThreadSingletonServiceImpl.java:193)
> >>        at org.apache.openejb.cdi.CdiBuilder.build(CdiBuilder.java:41)
> >>        at
> >> org.apache.openejb.assembler.classic.Assembler.
> >> createApplication(Assembler.java:908)
> >>        at
> >> org.apache.openejb.assembler.classic.Assembler.
> >> createApplication(Assembler.java:714)
> >>        at
> >> org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(
> >> TomcatWebAppBuilder.java:1254)
> >>        at
> >> org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(
> >> TomcatWebAppBuilder.java:1112)
> >>        at
> >> org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(
> >> GlobalListenerSupport.java:133)
> >>        at
> >> org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(
> >> LifecycleBase.java:94)
> >>        at
> >> org.apache.catalina.core.StandardContext.startInternal(
> >> StandardContext.java:5093)
> >>        at org.apache.catalina.util.LifecycleBase.start(
> >> LifecycleBase.java:152)
> >>        at
> >> org.apache.catalina.core.ContainerBase.addChildInternal(
> >> ContainerBase.java:726)
> >>        at org.apache.catalina.core.ContainerBase.addChild(
> >> ContainerBase.java:702)
> >>        at org.apache.catalina.core.StandardHost.addChild(
> >> StandardHost.java:734)
> >>        at
> >> org.apache.tomee.catalina.TomcatWebAppBuilder.deployWar(
> >> TomcatWebAppBuilder.java:644)
> >>        at
> >> org.apache.tomee.catalina.TomcatWebAppBuilder.deployWebApps(
> >> TomcatWebAppBuilder.java:584)
> >>        at
> >> org.apache.tomee.catalina.deployment.TomcatWebappDeployer.deploy(
> >> TomcatWebappDeployer.java:47)
> >>        at org.apache.openejb.assembler.DeployerEjb.deploy(
> >> DeployerEjb.java:180)
> >>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >>        at
> >> sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.java:
> >> 62)
> >>        at
> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(
> >> DelegatingMethodAccessorImpl.java:43)
> >>        at java.lang.reflect.Method.invoke(Method.java:497)
> >>        at
> >> org.apache.openejb.core.interceptor.ReflectionInvocationContext$
> >> Invocation.invoke(ReflectionInvocationContext.java:205)
> >>        at
> >> org.apache.openejb.core.interceptor.ReflectionInvocationContext.proce
> >> ed(
> >> ReflectionInvocationContext.java:186)
> >>        at
> >> org.apache.openejb.security.internal.InternalSecurityInterceptor.invo
> >> ke(
> >> InternalSecurityInterceptor.java:35)
> >>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >>        at
> >> sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.java:
> >> 62)
> >>        at
> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(
> >> DelegatingMethodAccessorImpl.java:43)
> >>        at java.lang.reflect.Method.invoke(Method.java:497)
> >>        at
> >> org.apache.openejb.core.interceptor.ReflectionInvocationContext$
> >> Invocation.invoke(ReflectionInvocationContext.java:205)
> >>        at
> >> org.apache.openejb.core.interceptor.ReflectionInvocationContext.proce
> >> ed(
> >> ReflectionInvocationContext.java:186)
> >>        at
> >> org.apache.openejb.monitoring.StatsInterceptor.record(
> >> StatsInterceptor.java:181)
> >>        at
> >> org.apache.openejb.monitoring.StatsInterceptor.invoke(
> >> StatsInterceptor.java:100)
> >>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >>        at
> >> sun.reflect.NativeMethodAccessorImpl.invoke(
> NativeMethodAccessorImpl.java:
> >> 62)
> >>        at
> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(
> >> DelegatingMethodAccessorImpl.java:43)
> >>        at java.lang.reflect.Method.invoke(Method.java:497)
> >>        at
> >> org.apache.openejb.core.interceptor.ReflectionInvocationContext$
> >> Invocation.invoke(ReflectionInvocationContext.java:205)
> >>        at
> >> org.apache.openejb.core.interceptor.ReflectionInvocationContext.proce
> >> ed(
> >> ReflectionInvocationContext.java:186)
> >>        at
> >> org.apache.openejb.core.interceptor.InterceptorStack.
> >> invoke(InterceptorStack.java:85)
> >>        at
> >> org.apache.openejb.core.singleton.SingletonContainer._
> >> invoke(SingletonContainer.java:256)
> >>        at
> >> org.apache.openejb.core.singleton.SingletonContainer.
> >> invoke(SingletonContainer.java:212)
> >>        at
> >> org.apache.openejb.server.ejbd.EjbRequestHandler.
> >> doEjbObject_BUSINESS_METHOD(EjbRequestHandler.java:370)
> >>        at
> >> org.apache.openejb.server.ejbd.EjbRequestHandler.processRequest(
> >> EjbRequestHandler.java:181)
> >>        at
> >> org.apache.openejb.server.ejbd.EjbDaemon.processEjbRequest(EjbDaemon.
> >> java:350)
> >>        at org.apache.openejb.server.ejbd.EjbDaemon.service(
> >> EjbDaemon.java:240)
> >>        at org.apache.openejb.server.ejbd.EjbServer.service(
> >> EjbServer.java:104)
> >>        at
> >> org.apache.openejb.server.httpd.ServerServlet.service(
> >> ServerServlet.java:58)
> >>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
> >>        at
> >> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
> >> ApplicationFilterChain.java:230)
> >>        at
> >> org.apache.catalina.core.ApplicationFilterChain.doFilter(
> >> ApplicationFilterChain.java:165)
> >>        at
> >> org.apache.catalina.core.StandardWrapperValve.invoke(
> >> StandardWrapperValve.java:198)
> >>        at
> >> org.apache.catalina.core.StandardContextValve.invoke(
> >> StandardContextValve.java:108)
> >>        at org.apache.tomee.catalina.OpenEJBValve.invoke(
> >> OpenEJBValve.java:44)
> >>        at
> >> org.apache.catalina.core.StandardHostValve.invoke(
> >> StandardHostValve.java:140)
> >>        at
> >> org.apache.catalina.valves.ErrorReportValve.invoke(
> >> ErrorReportValve.java:79)
> >>        at
> >> org.apache.catalina.valves.AbstractAccessLogValve.invoke(
> >> AbstractAccessLogValve.java:620)
> >>        at
> >> org.apache.catalina.core.StandardEngineValve.invoke(
> >> StandardEngineValve.java:87)
> >>        at
> >> org.apache.catalina.connector.CoyoteAdapter.service(
> >> CoyoteAdapter.java:349)
> >>        at
> >> org.apache.coyote.http11.Http11Processor.service(
> >> Http11Processor.java:1102)
> >>        at
> >> org.apache.coyote.AbstractProcessorLight.process(
> >> AbstractProcessorLight.java:66)
> >>        at
> >> org.apache.coyote.AbstractProtocol$ConnectionHandler.process(
> >> AbstractProtocol.java:788)
> >>        at
> >> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.
> >> run(NioEndpoint.java:1485)
> >>        at
> >> java.util.concurrent.ThreadPoolExecutor.runWorker(
> >> ThreadPoolExecutor.java:1142)
> >>        at
> >> java.util.concurrent.ThreadPoolExecutor$Worker.run(
> >> ThreadPoolExecutor.java:617)
> >>        at
> >> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(
> >> TaskThread.java:61)
> >>        at java.lang.Thread.run(Thread.java:745)
> >> Caused by: javax.persistence.PersistenceException: No persistence
> >> providers available for "camel" after trying the following discovered
> >> implementations:
> >> org.apache.openjpa.persistence.PersistenceProviderImpl,
> >> org.hibernate.ejb.HibernatePersistence
> >>        at
> >> javax.persistence.Persistence.createEntityManagerFactory(
> >> Persistence.java:179)
> >>        at
> >> org.springframework.orm.jpa.LocalEntityManagerFactoryBean.
> >> createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:96)
> >>        at
> >> org.springframework.orm.jpa.AbstractEntityManagerFactoryBe
> >> an.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:319)
> >>        at
> >> org.apache.camel.component.jpa.JpaEndpoint.createEntityManagerFactory
> >> (
> >> JpaEndpoint.java:510)
> >>        at
> >> org.apache.camel.component.jpa.JpaEndpoint.getEntityManagerFactory(
> >> JpaEndpoint.java:223)
> >>        at
> >>
org.apache.camel.component.jpa.JpaEndpoint.validate(JpaEndpoint.java:503)
> >>        at
> >> org.apache.camel.component.jpa.JpaEndpoint.createProducer(JpaEndpoint.
> >> java:145)
> >>        at
> >>
org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:439)
> >>        ... 131 more
> >> SEVERE - CDI Beans module deployment failed
> >>
> >> Is there a way to postpone the Camel Context initialisation be
Camel-CDI?
> >>
> >>
> >>
> >>
> >> --
> >> View this message in context: http://camel.465427.n5.nabble.
> >> com/Camel-JPA-JTA-Transaction-TomEE-tp5785642p5786071.html
> >> Sent from the Camel - Users mailing list archive at Nabble.com.
> >>

Reply via email to