Implementing the container callbacks
This AdviceBean code is completely legal. It compiles and runs. Right now, we don’t need anything in the callback methods, because the bean’s business logic doesn’t depend on anything else that happens at other times in the bean’s life. You’ll notice that we are saving the SessionContext parameter we get from the setSessionContext() container callback, but we aren’t using it in this code. Later in this chapter, you’ll learn why you might want to assign the context to an instance variable, and the circumstances under which you would put code in each of these callback methods.

When are container callbacks invoked?
For stateful session beans, when the bean transitions from one state to another.

| Before a bean is a bean (or even an object) it does not exist. The spec makes a big point of this, just in case there’s any confusion about something existing before it exists. So the state of non-existence is indeed a state that a bean can be in, even though it does not yet exist. When a session bean moves out of this state, the bean’s constructor runs, then setSessionContext(), and finally the ejbCreate() method. This is also the state a bean returns to after any one of these things occurs: bean times out, bean throws a system exception, or a client ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access