Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Exception in postCreate method?  RSS feed

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
if there is exception in postCreate() method in entity bean , data will be inserted in DB ???
Regards,
Murali
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!