• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

spring JtaTransactionManager with jetty

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello, I have been working on this problem for many hours and cannot fix it. I'm trying to use spring transactions within a service on jetty server but it seems for some reason that I cannot activate a transaction when I need it. My spring-context.xml is:

<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="AtomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close">
<property name="forceShutdown" value="false" />
</bean>
<bean id="AtomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
<property name="transactionTimeout" value="300" />
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="AtomikosTransactionManager" />
<property name="userTransaction" ref="AtomikosUserTransaction"/>
</bean>

then jetty-env.xml:
<New id="tx" class="org.mortbay.jetty.plus.naming.Transaction">
<Arg>
<New class="com.atomikos.icatch.jta.UserTransactionImp"/>
</Arg>

then I use spring transaction like this:

Boolean boo = (Boolean)transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status)
{
try {
write something on database

do something that calls Exception

} catch (ParseException e) {
status.setRollbackOnly();
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
status.setRollbackOnly();
// TODO Auto-generated catch block
e.printStackTrace();
}
return ret;
}
});

I noticed when I'm at the line "write something on database", the record is inserted on database, when at the line " do something that calls Exception" and then is callen status.setRollbackOnly(); nothing is rolledback on database. Please help. Bye

 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can you put the exception code here.
 
gianluca gian
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi! at the line "do something that calls Exception" I throw an SQLException for duplicate key that is catched in catch (Exception e) { and then it executes status.setRollbackOnly();
 
Hold that thought. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic