• Post Reply 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

transaction question in SessionBean

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's OK now.
Thank you very much.
[ May 22, 2003: Message edited by: Liz Lee ]
 
Nothing up my sleeve ... and ... presto! A tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic