Apache Camel 2.13.1 MyBatis Transaction not rolled back -


i have scenario, have first update row in 3 tables, insert new row each of tables. should in single batch of statements , rollback if fails.

scenario below e.g statement1 = update table1; statement2= update table2; statement3 =update table3; statement4 insert table1; statement5 insert table2; statement6 insert tables3 

the answer above question camel community use transactional client, issue transaction not being rolled on failure of 1 of mybatis statements.

e.g. exception case:the first 2 updates not rolled on failure of third 1 below:  .to("mybatis:usermapper.updateperson?statementtype=update") --- passed .to("mybatis:usermapper.updatecertificate8?statementtype=update") ---- passed .to("mybatis:usermapper.updateapplicationgroup?statementtype=update") ---- failed  **`am missing anything?`**      camel registry             simpleregistry registry = new simpleregistry();             datasourcetransactionmanager datasourcetransactionmanager = new datasourcetransactionmanager(             sqlsessionfactory.getconfiguration().getenvironment()                                                             .getdatasource());                             registry.put("transactionmanager",datasourcetransactionmanager);                             springtransactionpolicy springtransactionpolicy = new springtransactionpolicy();                             springtransactionpolicy.settransactionmanager(datasourcetransactionmanager);                             springtransactionpolicy.setpropagationbehaviorname("propagation_required");                             registry.put("propagation_required",springtransactionpolicy);                             camelcontext = new defaultcamelcontext(registry);                             camelcontext.settracing(true);                             camelcontext.start();       camel route:                     onexception(jmsexception.class)                     .handled(true).maximumredeliveries(0).end();                      onexception(illegalargumentexception.class)                     .handled(true).maximumredeliveries(0).rollback("rolling illegalargumentexception")                     .end();                      onexception(persistenceexception.class)                     .handled(true).maximumredeliveries(0).rollback("rolling transaction")                     .end();                      onexception(rollbackexchangeexception.class)                     .handled(false).maximumredeliveries(0).process(new cameltibcomessageprocessor())                     .end();   from("timer:foo?period=10000")  .policy("propagation_required")                                 .to("mybatis:usermapper.updateperson?statementtype=update")                                     .to("mybatis:usermapper.updatecertificate8?statementtype=update")                                     .to("mybatis:usermapper.updateapplicationgroup?statementtype=update")                                     .to("mybatis:usermapper.insertpersonfromcamsctsbridge?statementtype=insertlist&executortype=batch")                     .end();  

figured out, solution straightforward see link camel mybatis , mybatis-spring .

convert spring config java , have it. below did , worked fine.

add mybatis-spring maven dependency pom.

**------------------sample setup--------------------**  simpleregistry registry = new simpleregistry(); combopooleddatasource cpds = new combopooleddatasource(); cpds.setdriverclass("oracle.jdbc.driver.oracledriver"); cpds.setjdbcurl("jdbc_url"); cpds.setuser("username"); cpds.setpassword("password");  transactionawaredatasourceproxy transactionawaredatasourceproxy = new transactionawaredatasourceproxy(cpds); datasourcetransactionmanager transactionmanager = new datasourcetransactionmanager(transactionawaredatasourceproxy); registry.put("transactionmanager",transactionmanager); applicationcontext appcontext = new classpathxmlapplicationcontext(); sqlsessionfactorybean factorybean = new sqlsessionfactorybean();                         factorybean.setconfiglocation(appcontext.getresource("mapper/your_mybatis_config.xml")); factorybean.setdatasource(cpds);  springtransactionpolicy  propagationrequired = new springtransactionpolicy(); propagationrequired.settransactionmanager(transactionmanager); propagationrequired.setpropagationbehaviorname("propagation_required"); registry.put("propagation_required",propagationrequired);  springtransactionpolicy  propagationrequirednew= new springtransactionpolicy(); propagationrequirednew.settransactionmanager(transactionmanager); propagationrequirednew.setpropagationbehaviorname("propagation_requires_new"); registry.put("propagation_requires_new",propagationrequirednew);   camelcontext = new defaultcamelcontext(registry); camelcontext.settracing(true); camelcontext.start();   mybatiscomponent component = new mybatiscomponent(); component.setsqlsessionfactory(factorybean.getobject()); camelcontext.addcomponent("mybatis", component);  camelcontext.addroutes(new someroute());  

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -