Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Commit Rollback not working

 
Suma C S
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
 
Nicholas Cheung
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic