camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dimas <Dmitry_Shu...@kaltire.com>
Subject Camel JPA + JTA Transaction (TomEE)
Date Fri, 29 Jul 2016 15:57:18 GMT
Hi All,

I'm using TomEE (7.0.0) + Camel JMS + Camel CDI + Camel JPA  to receive and
store messages in the DB. Camel version is 2.17.2.

Out of the box, Camel JPA is failing because it is trying to access the
EntityTransaction of TomEE. 

08:36| ERROR | CamelLogger.java 156 | <openjpa-2.4.1-r422266:1730418
nonfatal user error> org.apache.openjpa.persistence.InvalidStateException:
You cannot access the EntityTransaction when using managed transactions.
	at
org.apache.openjpa.persistence.EntityManagerImpl.getTransaction(EntityManagerImpl.java:553)
	at
org.apache.openjpa.persistence.EntityManagerImpl.getTransaction(EntityManagerImpl.java:103)
	at
org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:67)
	at
org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
	at
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
	at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
	at org.apache.camel.component.jpa.JpaProducer.process(JpaProducer.java:62)
	at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)


In the 'transactionManeger' description column of Camel JPA doc
(http://camel.apache.org/jpa.html) there is some info about the ability to
set up JTA Transaction Manger 'Can be used to set a JTA transaction manager
(for integration with an EJB container).', but it's not clear how to do it
exactly.

I tried to use the doc page of Camel CDI (http://camel.apache.org/cdi.html),
the 'Referring beans from Endpoint URIs' section where it says that
following code should be used:

@Produces
@Named("jtaTransactionManager")
PlatformTransactionManager createTransactionManager(TransactionManager
transactionManager, UserTransaction userTransaction) {
    JtaTransactionManager jtaTransactionManager = new
JtaTransactionManager();
    jtaTransactionManager.setUserTransaction(userTransaction);
    jtaTransactionManager.setTransactionManager(transactionManager);
    jtaTransactionManager.afterPropertiesSet();
    return jtaTransactionManager;
}

And I'm using it in my route like this:

.to("jpa://com.some.Event?transactionManager=#jtaTransactionManager");

But if fails:

Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Api type
[javax.transaction.TransactionManager] is not found with the qualifiers 
Qualifiers: [@javax.enterprise.inject.Default()]
for injection into Method Injection Point, method name : 
createTransactionManager, Bean Owner : [PlatformTransactionManager,
WebBeansType:PRODUCERMETHOD, Name:jtaTransactionManager, API
Types:[java.lang.Object,org.springframework.transaction.PlatformTransactionManager],
Qualifiers:[javax.enterprise.inject.Default,javax.enterprise.inject.Any,javax.inject.Named]]
	at
org.apache.webbeans.util.InjectionExceptionUtil.throwUnsatisfiedResolutionException(InjectionExceptionUtil.java:65)
	at
org.apache.webbeans.container.InjectionResolver.checkInjectionPoint(InjectionResolver.java:234)
	at
org.apache.webbeans.container.BeanManagerImpl.validate(BeanManagerImpl.java:1199)
	at org.apache.webbeans.util.WebBeansUtil.validate(WebBeansUtil.java:1709)
	at
org.apache.webbeans.config.BeansDeployer.validate(BeansDeployer.java:909)
	at
org.apache.webbeans.config.BeansDeployer.validateInjectionPoints(BeansDeployer.java:820)
	at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:305)


Looks like i have to create producer for
javax.transaction.TransactionManager, not sure how to do it. Or may be I'm
doing something totally wrong here..

Cheers,
Dmitry



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-JPA-JTA-Transaction-TomEE-tp5785642.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message