• 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Commit Rollback not working  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using WSAD 5.0.0. to develop Enterprise java application and connecting to DB2 7.2 using Default DB2 JDBC Provider (COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource).
One of the EJBs (EJB 2.0) invokes another java class (DAO) which inturn executes a set of sql statements.
The EJB is a stateless Session bean with Container Managed Txn. Container Txn type is Required.
IN the DAO, I am setting autoCommit(false). rollback() or commit()is executed based on the results of the query.
However, roll back is not happening in case of an exception (SQLException).

Please let me know where I am wrong.

Thanks
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


IN the DAO, I am setting autoCommit(false). rollback() or commit()is executed based on the results of the query.


You have no need to set anything if you are using CMT. The container will determine everything for you.


However, roll back is not happening in case of an exception (SQLException).


java.sql.SQLException is a checked exception, and thus, the transaction will not be rollback. You may need to create another exception, say, DAOSysException, which extends RuntimeException, in order to let the container rollback your transactions.

Noticed that automatically rollback will only be performed, when the container receive RuntimeException, not checked exception.

Nick
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!