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

connection rollback/ atomic transaction problem

Nitin Deshmukh
Greenhorn

Joined: Nov 28, 2007
Posts: 9
Hi,

I have a problem. I am using JSF1.1, EJB2.x, JDBC and weblogic8.1sp6. the structure of the application is like this, jsf bean calls facade bean(which is stateless session bean) method. facade bean method calls dao method to perform database insert/updates. the trasaction attribute of facadebean's method is set to required in ejb-jar.xml.
now I create connection in the dao method and pass that to further dao methods. I have connection.setAutoCommit(false) in the dao methods. Problem is that in case of exception, rollback is not working. whatever updates are performed before the exception, get commited to the database, whether I specify rollback in the catch block or not. If I rollback in the dao method, I get the following exception when trying to rollback.
can anyone help me please?


here are my methods


Nitin
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Are you calling setRollbackOnly() in your EJB method when you catch your application exception?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Nitin Deshmukh
Greenhorn

Joined: Nov 28, 2007
Posts: 9
no, I am not. how do I call setRollbackOnly method? as far as I know, there is no such method in the session bean.
Nitin Deshmukh
Greenhorn

Joined: Nov 28, 2007
Posts: 9
hi,
found out that setRollBackOnly() is a method of EJBContext. used and tested this method in a dummy method and it seems to work.
thanks a lot for the response.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Nitin Deshmukh:
hi,
found out that setRollBackOnly() is a method of EJBContext. used and tested this method in a dummy method and it seems to work.
thanks a lot for the response.


Yes indeed, it is called on the EJBContext. This is one of the cornerstones of EJB CMT. An EJB method that is running in a container managed transaction needs to know when an exception == a transaction rollback. It is perfectly possible for your method to handle a situation where you encounter an exception and you want the transaction to be committed anyway. So you need to tell the container that it should rollback via setRollbackOnly().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connection rollback/ atomic transaction problem
 
Similar Threads
JDBC connection and transactions
ExceptionInInitializerError
Testing Database Connection
EJB3 RollBack Txn Error
Exception