This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply Bookmark "Ejb 3.0 rollback doesnot work" Watch "Ejb 3.0 rollback doesnot work" New topic
Author

Ejb 3.0 rollback doesnot work

prashant korade
Greenhorn

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;




@Stateless
//@javax.ejb.ApplicationException(rollback = true)
@TransactionManagement(javax.ejb.TransactionManagementType.BEAN)
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 {
UserTx.begin();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:test");
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*************");
if(1==1){
throw new Myexception("HI"); //to throw exception
}
UserTx.commit();
} catch (Myexception e) {
try {
UserTx.rollback();
System.out.println(e);
}
catch (SystemException ex) {
Logger.getLogger(TestEjbBean.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(e);
}catch(Exception r){}



return val;
}


}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ejb 3.0 rollback doesnot work
 
Similar Threads
JDBC and MS Excel
insert statement is not working
Null pointer exception in con.createStatement();
fill selectOneMenu from database
Insert and MoveFirst