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 transaction question in SessionBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "transaction question in SessionBean" Watch "transaction question in SessionBean" New topic

transaction question in SessionBean

Liz Lee

Joined: Feb 23, 2003
Posts: 6
suppose there are two EntityBean A and B with one-one relationship. If A is deleted, B also should be delete.
There is a mothodA() in SessionBean.
public void methodA() throws Exception{
A a = home.findByPrimaryKey(aId);
B b = a.getB();
//... do something others
// (1)
The session bean is stateless, and methodA's transaction attribute is 'Required'.
According to the session facade pattern, I consider that there should be only one transaction in methodA, so if the exception is thrown, transaction should be rolled back. Both a and b should be still in DB.
But now in fact, b is deleted, a is still in DB. I don'w know what's wrong with my configuration.
Malar Sundar

Joined: May 22, 2003
Posts: 7
You should handle exceptions and mark the transaction to rollback, so that the container knows whether to commit or rollback.
// session bean method...
methodA() throws Exception
try {
// call b.remove();
// call a.remove();
catch(Throwable t)
// throw new Exception(t.getMessage());
// or throw your application exception...
Liz Lee

Joined: Feb 23, 2003
Posts: 6
It's OK now.
Thank you very much.
[ May 22, 2003: Message edited by: Liz Lee ]
Consider Paul's rocket mass heater.
subject: transaction question in SessionBean
It's not a secret anymore!