Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Transaction not rolling back

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Weblogic 6.1 sp3 and Sybase 12.5 DB.

I have a peice of code....something like this -


METHOD A
Look up userTx;
try{
userTx.begin();
getTxDataSource().getConnection();
update table A;
call METGOD B
userTx.commit();
}
catch(exception e){
userTx.rollback();
}



METHOD B
try{
Look up userTx;
realize its under a TX context so doesnt call begin;
getTxDataSource().getConnection();
Read Table A and Update Table B;
Not my TX so dont commit;
}catch(Exception ex){
Not my TX so mark for rollback;
throw ex;
}

Both Table A and Table B are in the same database.

Now when Method B throws an exception....the DB changes are not getting rolled back.

Can someone tell me , what could possibly be going wrong here ?
I am not using a XADataSource for my TX DataSource , i use the regular connection pool (com.sybase.jdbc2.jdbc.SybDriver is the JDBC driver).
But in the DataSource config i set EnableTwoPhaseCommit=true.

I am thinking....do i have to use javax.transaction.xa package....i am not using it in my code so far.

Please suggest
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I suspect your userTxn objects are different. Pass the object as argument to method B and use the same connection also. It should work.

regards,
Rajiv
 
Pappu Kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UserTx part is OK , when check for the TX status inside Method B...it shows as TX ACTIVE status.
 
Pappu Kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another thing if i do a "select @@spid" query inside METHODA and METHODB , they return deifferent spid's. I believe that somehow the app server is not handling the TX DATASOURCE well enough...the spid's have to be the same for one transaction.
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic