| Author |
transaction question in SessionBean
|
Liz Lee
Greenhorn
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(); b.remove(); //... do something others // (1) a.remove(); } 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
Greenhorn
Joined: May 22, 2003
Posts: 7
|
|
Hi, 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) { getSessionContext).setRollbackOnly); // throw new Exception(t.getMessage()); // or throw your application exception... } }
|
 |
Liz Lee
Greenhorn
Joined: Feb 23, 2003
Posts: 6
|
|
It's OK now. Thank you very much. [ May 22, 2003: Message edited by: Liz Lee ]
|
 |
 |
|
|
subject: transaction question in SessionBean
|
|
|