File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes Commit Rollback not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "Commit Rollback not working" Watch "Commit Rollback not working" New topic
Author

Commit Rollback not working

Suma C S
Greenhorn

Joined: Aug 22, 2004
Posts: 4
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

Joined: Nov 07, 2003
Posts: 4982

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


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Commit Rollback not working