Back Forum Reply New

@Transaction doesnt work with JTA(Atomikos)

mit();       } catch (Exception e) {System.out.println(quot;exception caughtquot;);userTransactionManager.rollback();e.printStackTrace();       }
       System.out.println(quot;cron runningquot; + i);   }
But the same doesnt work wheni use @Transaction annotation on teh same method. i .eCode:
   @Scheduled(fixedDelay = 10 * 1000)   @Transaction   public void perform() throws Exception {performTransaction();      //this methos throws runtime(java.lang.runtime) exception when there is a error       System.out.println(quot;cron runningquot; + i);   }
My spring configuration are as followsCode:

lt;util:properties id=quot;databasePropertiesquot; location=quot;classpath:tspex-database.propertiesquot;/gt;

lt;bean id=quot;dataSourcequot; class=quot;com.atomikos.jdbc.AtomikosDataSourceBeanquot;
init-method=quot;initquot; destroy-method=quot;closequot;gt;
lt;property name=quot;uniqueResourceNamequot; value=quot;MAIN-MYSQL-CONNECTIONquot; /gt;
lt;property name=quot;poolSizequot; value=quot;2quot; /gt;       lt;property name=quot;xaDataSourceClassNamequot; value=quot;com.mysql.jdbc.jdbc2.optional.MysqlXADataSourcequot;gt;lt;/propertygt;       lt;property name=quot;xaPropertiesquot; ref=quot;databasePropertiesquot;/gt;
lt;/beangt;

lt;tx:annotation-driven transaction-manager=quot;transactionManagerquot; /gt;

lt;!-- Construct Atomikos UserTransactionManager, needed to configure Spring --gt;
lt;bean id=quot;atomikosTransactionManagerquot; class=quot;com.atomikos.icatch.jta.UserTransactionManagerquot;
init-method=quot;initquot; destroy-method=quot;closequot;gt;
lt;!-- when close is called, should we force transactions to terminate or
not? --gt;
lt;property name=quot;forceShutdownquot;gt;
lt;valuegt;truelt;/valuegt;
lt;/propertygt;

lt;/beangt;

lt;!-- Also use Atomikos UserTransactionImp, needed to configure Spring --gt;
lt;bean id=quot;atomikosUserTransactionquot; class=quot;com.atomikos.icatch.jta.UserTransactionImpquot;gt;
lt;/beangt;

lt;!-- Configure the Spring framework to use JTA transactions from Atomikos --gt;
lt;bean id=quot;transactionManagerquot;
class=quot;org..transaction.jta.JtaTransactionManagerquot;gt;
lt;property name=quot;transactionManagerquot;gt;
lt;ref bean=quot;atomikosTransactionManagerquot; /gt;
lt;/propertygt;
lt;property name=quot;userTransactionquot;gt;
lt;ref bean=quot;atomikosUserTransactionquot; /gt;
lt;/propertygt;
lt;/beangt;i got it working . Teh issue was i was testing by writing a @scheduled  method in teh same class which had a method @transactional.

Since by default spring uses proxies , calls wihing the same bean doesnt go through proxy. By moving teh @scheduled to another bean this worked fine.
¥
Back Forum Reply New