wood burning stoves 2.0*
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
Author

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 sessionbean.as 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
{


try
{
*************other business processes******************

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

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

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

rs=stmt.executeQuery(query1);
rs1=stmt.executeQuery(query2);

if(rs.next)
int cnt1=rs.getInt(1);

if(rs1.next)
int cnt2=rs.getInt(1);

if(cnt1 != cnt2)
{
flag =true;
}

if(flag)
throw new MismatchException("mismatch exception ");

}
catch(Exception e)
{
ctx.rollBackOnly();
}
}

EntityBean
***********

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

public void ejbStore() throws javax.ejb.EJBException
{
try
{
if(isDirty)
{
isDirty = false;
EmployeeMaster EmployeeMasterDAO = new EmployeeMaster();
EmployeeMasterDAO.store(employeeMasterDOB);
}

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

EmployeeMasterDAO
****************

store(employeeMasterDOB)
{
data will be inserted in empcharges and deptcharges tables...
}
Paul Sturrock
Bartender

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
 
 
subject: how to rollback the transaction in ejbStore()