• 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

EJB TransactionRolledback Exception

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi experts,
Im working on some ticket booking system and had encounter something that i don't understand.
Whenever i add create a Entity Bean, and if there is a existing record with the same primary key, it will throw me a TransactionRolledbackException. Everything works well if i throw the exception to the web tier(Servlet) and handle it. But i wanted to store some value into the Exception so that my Servlet can get it, i try creating a Customoize Exception that extends TransactionRolledbackException like this :

public class TicketBookedException extends TransactionRolledbackException {
private String x;
//getter and setter
}

and throw this Exception to the web tier :

try {
//book ticket
} catch (TransactionRolledbackException e) {
TicketBookedException tbe = new TicketBookedException();
tbe.setX("xxx");
throw tbe;
}

but when i catch it in my web tier :

try {
bookingManager.book();
} catch (TransactionRolledbackException e) {
TicketBookedException tbe = (TicketBookedException)e;
//...
}

i keep getting a ClassCastException. im quite sure this is legal because i try it on a non ejb senerio by creating 3 simple java class and it works (throwing NullPointerException).

And the other thing im not sure is that in my EJB that use the entity bean. when i catch the TransactionRolledbackException , i must throw it to the web tier or i will get a error as if im not handling it. cant i just handle it silently at the ejb.

Thanks for reading. Hope someone will enlighten me
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic