I also had the problem of combining jpa and camel transactions a while ago
and created an example and documentation for XA setup.
See:
https://github.com/Talend/tesb-rt-se/blob/master/examples/tesb/ebook/xa-docs.md
https://github.com/Talend/tesb-rt-se/tree/master/examples/tesb/ebook

Camel route:
https://github.com/Talend/tesb-rt-se/blob/master/examples/tesb/ebook/ebook-importer/src/main/java/org/talend/esb/examples/ebook/importer/ImportRoutes.java

The example reads from a xml file, parses each record into a jaxb bean and
sends the serialized bean to jms.
Then it reads from jms into a bean again and writes into a database using
jpa. This second flow coordinates a camel jms transaction and a jpa db
transaction using jta.

You can find the necessary jta setup in the camel context:
https://github.com/Talend/tesb-rt-se/blob/master/examples/tesb/ebook/ebook-connectionfactory/src/main/resources/OSGI-INF/blueprint/blueprint.xml

and the connection factory definition:
https://github.com/Talend/tesb-rt-se/blob/master/examples/tesb/ebook/ebook-importer/src/main/resources/OSGI-INF/blueprint/blueprint.xml

I think what is not mentioned in the example is that you have to setup an
xa ready datasource (at least I did not find it) using pax-jdbc.
See
https://ops4j1.jira.com/wiki/spaces/PAXJDBC/pages/119078914/Pooling+and+XA+support+in+1.0.0
https://ops4j1.jira.com/wiki/spaces/PAXJDBC/pages/61767716/Pooling+and+XA+support+for+DataSourceFactory

Cheers
Christian


Am Mi., 5. Dez. 2018 um 15:43 Uhr schrieb Niehues, Christian <
[email protected]>:

> Hi,
>
> I have a server application running in karaf and I have problems to
> combine transactions defined in spring/camel and code having @Transactional
> annotation.
>
> In my blueprint.xml I have defined something like this:
>
> *   <reference id="jtaTransactionManager"
> interface="javax.transaction.TransactionManager" />*
> *   <reference id="userTransaction"
> interface="javax.transaction.UserTransaction" />*
>
> *   <bean id="transactionManager"
> class="org.springframework.transaction.jta.JtaTransactionManager">*
> *       <argument ref="jtaTransactionManager" />*
> *       <argument ref="userTransaction" />*
> *   </bean>*
>
> *   <bean id="PROPAGATION_REQUIRES_NEW"
> class="org.apache.camel.spring.spi.SpringTransactionPolicy">*
> *       <property name="transactionManager" ref="transactionManager" />*
> *       <property name="propagationBehaviorName"
> value="PROPAGATION_REQUIRES_NEW" />*
> *   </bean>*
>
> So I start a new transaction by using *PROPAGATION_REQUIRES_NEW *in a
> camel route. The camel route leads to a WebService endpoint. Anywhere in
> the underlying code where I use @Transactional and get a EntityManager
> injected I can see that the transaction is handled by a coordination from
> aries-jpa and gets committed by the uppermost @Transactional annotation.
> But I want that the underlying code uses the transaction created by the
> *PROPAGATION_REQUIRES_NEW* in the camel route so I am maybe able to
> rollback the transaction inside the camel route. How to achieve this? Do I
> have to use a TransactionManager from aries-jpa instead?
>
> Thanks in advance,
> Christian
>
>

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

Computer Scientist
http://www.adobe.com

Reply via email to