File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Ejb 3.0 rollback doesnot work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Ejb 3.0 rollback doesnot work" Watch "Ejb 3.0 rollback doesnot work" New topic

Ejb 3.0 rollback doesnot work

prashant korade

Joined: Dec 09, 2008
Posts: 1
I have written following simple code to check how rollback works in case of Transactions.
But its not working. It still inserts data in database.

package stateless;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import java.sql.*;
import javax.annotation.Resource;

import javax.ejb.TransactionManagement;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;

//@javax.ejb.ApplicationException(rollback = true)
public class TestEjbBean extends Myexception implements TestEjbRemote, TestEjbLocal{
@Resource private javax.transaction.UserTransaction UserTx;
Connection con;
int val=0;

public String getMessage() {
return "Hello Ejb World";
// @TransactionAttribute(javax.ejb.TransactionAttributeType.REQUIRED)
public int InsertData(){
try {
Statement st = con.createStatement();
val=st.executeUpdate("INSERT INTO MulTable VALUES(21,13)");
System.out.println("**********AFTER INSERTING INT VALUES*************");
//st.executeUpdate("INSERT INTO MulTable VALUES(a,b)");
//System.out.println("**********AFTER INSERTING WRONG VALUES*************");
throw new Myexception("HI"); //to throw exception
} catch (Myexception e) {
try {
catch (SystemException ex) {
Logger.getLogger(TestEjbBean.class.getName()).log(Level.SEVERE, null, ex);
}catch(Exception r){}

return val;

I agree. Here's the link:
subject: Ejb 3.0 rollback doesnot work
jQuery in Action, 3rd edition