• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB TransactionRolledback Exception  RSS feed

yc lim
Posts: 14
  • Mark post as helpful
  • send pies
  • 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();
throw tbe;

but when i catch it in my web tier :

try {
} 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
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!