Originally posted by Valentin Crettaz:
I have summarized what beans can and cannot do during their lifecycle in my cheat sheet about life cycles and allowed operations of EJBs.
Since the bean uses CMT, answer C is wrong and can be eliminated right away.
On the left of page 4 of my cheat sheet, you can see that stateless CMT session beans can only invoke getEJB(Local)Home() (A) and access the JNDI context java:comp/env during the invocation of setSessionContext(). After setSessionContext() is done executing, ejbCreate() will be called and it will be allowed to call getEJB(Local)Object() (B,H) in addition to what setSessionContext() was allowed to. Finally, business methods may invoke any callback. So strictly speaking, the correct answers to this question should be B and H since just after setSessionContext(), ejbCreate() will be called and it may not invoke D,E,F,G.
Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
Originally posted by Valentin Crettaz:
Sorry Valentin, in this case the right answer should be All but B and H (I know that you knew).
Thanks for the reminder Marco... I really needed some rest on Friday, I guess![]()
Do we own anything to you???
I'm doing this for the benefit of the community. I won't spit on a beer, though![]()
Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
To come back to the question, I disagree with you both (Valentin and Marc): According to Valentin's cheat sheet I would mark the following answers:
For a stateless session bean usig CMT
(A) getEJBLocalHome must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> wrong, it can be invoked in setSessionContext()
(B) getEJBObject must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, it can be invoked in ejbCreate, in a business method and in ejbRemove
(C) getUserTransaction must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> wrong, this method should never be invoked for CMT
(D) getCallerPrincipal must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, should only be invoked in a business method, that's definitely after setSessionContext
(E) isCallerInRole must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, should only be invoked in a business method, that's definitely after setSessionContext
(F) setRollbackOnly must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, should only be invoked in a business method, that's definitely after setSessionContext
(G) getCallerPrincipal must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, should only be invoked in a business method, that's definitely after setSessionContext
(H) getEJBLocalObject must NOT be invoked on a bean's EJBContext until AFTER the execution of the setSessionContext ==> true, it can be invoked in ejbCreate, in a business method and in ejbRemove
So the solution would be
B,D,E,F,G,H
(or, strictly only B,H then Valentin's answer would be right...)
Originally posted by Severin St�ckli:
Ohw boys, didn't you read the Head First?
...
Beer, or something stronger, is called for when you pass the exam[/b]![]()
Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |