> I only still see some difference when using seda instead of direct in camel routes, so there seems to be some issue when using different threads. Yes. A transaction by default only works on the same thread.
Christian Am Do., 6. Dez. 2018 um 14:46 Uhr schrieb Niehues, Christian < christian.nieh...@its-digital.de>: > Hi Christian, > > > Thanks for the fast and detailed answer. > > > I think I already used a XADatasource because of the properties set in my > datasource configuration: > > pool=dbcp2 > xa=true > > Question about that: I saw you can also use pool=aries but when I try to > use it I get no EntityManager. So do I have to change additional things? > > > I think my problem was that I didn't use a pooled connectionfactory. Since > I use XaPooledConnectionFactory like in your example it seems to work. > > I only still see some difference when using seda instead of direct in > camel routes, so there seems to be some issue when using different threads. > > Also I need to check if it works when using cluster setup. > > > Thanks > > Christian > > ------------------------------ > *Von:* Christian Schneider <ch...@die-schneider.net> > *Gesendet:* Mittwoch, 5. Dezember 2018 16:30:21 > *An:* user@aries.apache.org > *Betreff:* Re: Coordination between spring JtaTransactionManager and > Aries JPA > > 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 < > christian.nieh...@its-digital.de>: > >> 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 > > -- -- Christian Schneider http://www.liquid-reality.de Computer Scientist http://www.adobe.com