This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Callbacks with System Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Callbacks with System Exceptions" Watch "Callbacks with System Exceptions" New topic
Author

Callbacks with System Exceptions

Jarrod Felino
Greenhorn

Joined: Nov 15, 2008
Posts: 26
On page 361 of the Core EJB specification it states that:

Discard instance means that the container must not invoke any business methods or container callbacks
on the instance


Now if my Stateless session bean throws a RuntimeException this would mean that the @PostConstruct callback should not get get called:



However when I invoke the add() method the @PostConstruct method is getting called every time?
Jarrod Felino
Greenhorn

Joined: Nov 15, 2008
Posts: 26
This is from section 12.4.2 of the EJB Core Specification.

The PreDestroy callbacks are not invoked when the bean and the interceptors are discarded as a
result of such exceptions: the lifecycle callback interceptor methods in the chain should perform any
necessary clean-up operations as the interceptor chain unwinds.


Is this because I am using JBoss and another Interceptor is handling the exception?
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
However when I invoke the add() method the @PostConstruct method is getting called every time?


I don't see any @PostConstruct in your code.


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Jarrod Felino
Greenhorn

Joined: Nov 15, 2008
Posts: 26
Sorry I meant @PreDestroy
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
After creating the bean, the add method is being called. Then it throws exception, so as a part of unwinding process, the @PreDestroy annotation is being called.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Callbacks with System Exceptions