Hi,
I have created a project containing a persistence and service layer.
Transactions demarcations are defined at the level of the service like
this
<service ref="incidentService"
interface="org.apache.camel.example.reportincident.service.IncidentService"/>
<bean id="incidentService"
class="org.apache.camel.example.reportincident.service.impl.IncidentServiceImpl">
<tx:transaction method="*" value="Required" />
<property name="incidentDAO">
<reference
interface="org.apache.camel.example.reportincident.dao.IncidentDAO"/>
</property>
</bean>
Persistence has been defined as presented here after
<bean id="incidentDAO"
class="org.apache.camel.example.reportincident.dao.impl.IncidentDAOImpl">
<jpa:context property="entityManager" unitname="ReportIncident"/>
</bean>
<service ref="incidentDAO"
interface="org.apache.camel.example.reportincident.dao.IncidentDAO">
</service>
>From a Camel transactional route, I commit or generate a rollback in
case of error.
<!-- SpringTransactionPolicy bean -->
<bean id="PROPAGATION_REQUIRED"
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager">
<osgi:reference
interface="org.springframework.transaction.PlatformTransactionManager"/>
</property>
<property name="propagationBehaviorName"
value="PROPAGATION_REQUIRED"/>
</bean>
<route>
<from uri="activemq:queue:in"/>
<transacted ref="PROPAGATION_REQUIRED"/>
<doTry>
<bean ref="incidentSaver" method="process"/>
<bean ref="generateError" method="generateError"/>
<doCatch>
<exception>java.lang.Exception</exception>
<rollback message=">>> Exception generated. We
rollback !!"/>
</doCatch>
</doTry>
</route>
Services exposed :
Apache Aries Transaction Manager (1896) provides:
-------------------------------------------------
org.osgi.service.cm.ManagedServiceFactory
javax.transaction.TransactionManager,
javax.transaction.TransactionSynchronizationRegistry,
javax.transaction.UserTransaction,
org.apache.geronimo.transaction.manager.RecoverableTransactionManager,
org.springframework.transaction.PlatformTransactionManager
Everything works fine as I'm able from my camel route to call the
service layer (=POJO) and insert data in the MySQL DB. Unfortunately,
when I generate an error and a rollback occurs in camel, this one is
not propagated back and data are inserted.
Does anybody has a trick to solve this ?
Regards,
Charles Moulliard
Sr. Principal Solution Architect - FuseSource
Apache Committer
Blog : http://cmoulliard.blogspot.com
Twitter : http://twitter.com/cmoulliard
Linkedin : http://www.linkedin.com/in/charlesmoulliard
Skype: cmoulliard