Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 12th, 2004, 08:32 AM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default EJB - TransactionRolledbackException

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run ejb haribaskerk EJB 0 February 14th, 2007 04:59 AM
EJB gillani EJB 1 July 1st, 2006 07:57 PM
J2EE with out EJB arun_sunmic J2EE 2 January 16th, 2006 07:16 AM
EJB 3.0 GLichten BOOK: Expert One-on-One J2EE Design and Development 0 December 1st, 2005 06:02 AM
jsp AND EJB rokkam BOOK: Expert One-on-One J2EE Design and Development 1 April 8th, 2004 01:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.