File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JBoss/WildFly and the fly likes how to rollback the transaction in ejbStore() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Reply locked New topic

how to rollback the transaction in ejbStore()

maha laxmi
Ranch Hand

Joined: Sep 23, 2005
Posts: 68
we are using mvc-2 architecture.when i want to modify the employee details what we r doing is from controller it will goes to modifyEmployee method in u can see in sessionbean code i set setEmployeeMaster(employeeMaster) inturn it will call setEmployeeMaster in Entity bean where i am making isDirtyFlag is true;we r using EJB1.1;

after that code in sessionbean i am checking whether sizes of empcharges and deptcharges tables does not equal then throw exception and total transaction should be rollback.

At the time of retrieving the count of two tables even data is not inserted in two tables in ejbStore() because ejbStore will be called by the container;after executing full modifyEmployee() method only container is calling ejbStore where i am inserting data in two tables;before transaction is commit conatiner is calling ejbStore();

my requirment is i have to check whether in two tables any mismatch is going ;

how can i write this in this type of scenario?but while creating employee details i have put same condition where ejbCreate will be called at that time transaction is rolledback.(when i say home = (EmployeeEntityHome)ictx.lookup("EmployeeEntityBean");
remote = (EmployeeEntity)home.create(); container is calling immediately ejbCreate);

but in this case container is not calling immediately ejbStore when i say remote.setEmployeeMaster(employeeMaster);

i have written Pseudo code may be some errors are there;i am using JBoss

Session bean

modifyEmployee(EmpMaster empMaster) thrpws MismatchException

*************other business processes******************

ictx = new InitialContext();
home = (EmployeeEntityHome)ictx.lookup("EmployeeEntityBean");
remote = (EmployeeEntity)home.findByPrimaryKey(new Long(empMaster.empNo));

*************other business processes******************

query1="select count(*) from empcharges where empno='*****'"
query2="select count(*) from deptcharges where deptpno='*****'"


int cnt1=rs.getInt(1);

int cnt2=rs.getInt(1);

if(cnt1 != cnt2)
flag =true;

throw new MismatchException("mismatch exception ");

catch(Exception e)


public void setEmployeeMaster(EmployeeMasterDOB employeeMasterDOB)
this.employeeMasterDOB = employeeMasterDOB;
isDirty = true;

public void ejbStore() throws javax.ejb.EJBException
isDirty = false;
EmployeeMaster EmployeeMasterDAO = new EmployeeMaster();;

catch(Exception ex)
logger.error(FILE_NAME+"[ejbStore()] -> "+ex.toString());
throw new EJBException(ex.getMessage());


data will be inserted in empcharges and deptcharges tables...
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Please don't post the same topic in more than one place. you've got more chance of an answer in the EJB forum, so I'm closing this one.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
I agree. Here's the link:
subject: how to rollback the transaction in ejbStore()
jQuery in Action, 3rd edition