*
The moose likes EJB and other Java EE Technologies and the fly likes Exception in postCreate method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Exception in postCreate method?" Watch "Exception in postCreate method?" New topic
Author

Exception in postCreate method?

Murali Mohan
Ranch Hand

Joined: Jul 07, 2003
Posts: 47
Hi ,
if there is exception in postCreate() method in entity bean , data will be inserted in DB ???
Regards,
Murali
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Murali,
Let's refresh a few points.
  • If a checked exception is thrown then the container won't destroy the instance or mark the transaction for rollback.
  • It an unchecked exception is thrown, the transaction is marked for rollback and the bean instance is killed.

  • Since CreateException is a checked exception, if it is thrown by ejbPostCreate(), then nothing special happens according to the rules we just summarized. The data from ejbCreate() will still be in the database if we don't do anything besides throw an exception. (Remember that ejbCreate() and ejbPostCreate() run in the same transaction.)
    What we need to do is set the transaction so that it gets rolled back before we throw the exception. (Or we could throw an EJBException, but that wouldn't be what the client expects, so go with the other solution.) Does that help answer your question?


    Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Exception in postCreate method?
     
    Similar Threads
    CMP Life CyCle
    At what stage, the life cycle of a CMP bean can be assumed to be started ?
    HFEJB doubt on Page 318?
    Three questions
    Security and Transactions within @PrePassivate & @PostActivate