Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to rollback the transaction in ejbStore()

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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...
}
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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.
    Bookmark Topic Watch Topic
  • New Topic