Forums Register Login

EJB TransactionRolledback Exception

+Pie Number of slices to send: Send
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
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 430 times.
Similar Threads
Trying to instantiate my middle tier class??see code
Method SetRollbackOnly don't work!
problem with transaction roll back
unable to catch EJBException from ejbstore in facade
problem in throwing Exception from Bean
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:59:06.