Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ejbCreate(..) / ejbPostCreate(..) and appli exceptions

 
Binoj Viswanathan
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ejbCreate(..)/ejbPostCreate(..) and Application exceptions

hi,
as per ejb spec if the client starts txn and if u thro appli exce..n in ur bean instance container wont rollback the txn automaticali.but vat i experienced while throwing application exce..on in ejbCreate(..)/ejbPostCreate(..) is
scenario 1:
(a) client started txn
(b)all methds in Entity bean runs in "required" txn attr
(c)following code in ejbPostCreate(..)
throw new TestAppliException("errrrrrr");
(d)no entity is created in DB

scenario 2:
(a) client pgm invokes meth without creating txn
(b)all methds in Entity bean runs in "required" txn attr
(c)following code in ejbPostCreate(..)
throw new TestAppliException("errrrrrr");
(d)no entity is created in DB

scenario 3:
(a) client started txn
(b)all methds in Entity bean runs in "required" txn attr
(c)following code in ejbPostCreate(..)
throw new EJBException();
(d)no entity is created in DB

scenario 4:
(a) client pgm invokes meth without creating txn
(b)all methds in Entity bean runs in "required" txn attr
(c)following code in ejbPostCreate(..)
throw new EJBException();
(d)no entity is created in DB


scenario 5:
(a) client started txn
(b)all methds in Entity bean runs in "required" txn attr
(c)following code in ejbCreate(..)
throw new TestAppliException("errrrrrr");
(d)no entity is created in DB

scenario 6:
(a) client pgm invokes meth without creating txn
(b)all methds in Entity bean runs in "required" txn attr
(c)following code in ejbCreate(..)
throw new EJBException();
(d)no entity is created in DB

the bottom line for this scenarios:
"either txn is started by the container or EJB client for both appli and non-appli exception if its thrown from either ejbCreate() or ejbPostCreate(), entity wont b created in the DB."

its sure that in case of scenario 3,4 and 6 , entity wont b created in the DB. but vat abt 1,2 and 5?

can anione coment on this?

thanx in advance
Bin
 
Binoj Viswanathan
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
???
 
Keerthi P
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An application exception thrown from the ejbCreate() [and ejbPostCreate()] method indicates that the entity's state could not be properly initialized. The entity's state is considered initialized successfully only if both the ejbCreate() and the matching ejbPostCreate() complete successfully. If any of these methods throw an exception (checked or unchecked) the container rollsback the transaction to restore data integrity.

Moreover, the container may create the entity in the database immediately, or it can defer it to a later time (for example to the time after the matching ejbPostCreate() has been called, or to the end of the transaction), depending on the caching strategy it uses. The container rolls back the transaction if ejbCreate() or ejbPostCreate() method throws javax.ejb.CreateException. So should be case for any application exception, like TestAppliException, thrown from the method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic