ETS Question
For a stateless session bean
Given the below code
Options:
a) It can be a business method
b) It can be a @PostConstruct method
c) It can be a @Remove method
d) This code is invalid in any stateless session bean
e) It may be DI method such as setSessionContext.
Answer: It can be a business method.
I invoked the lookup() from PostConstruct, PreDestroy and business method and it worked fine. This means that above method
can be any one of PostConstruct, PreDestroy and business method and not just business method. Please clarify.
ETS Answer: A stateless session bean cannot access resource managers in @PostConstruct methods.
Result:
12:18:12,796 INFO [STDOUT] Start:TestBeanIC.init()
12:18:12,796 INFO [STDOUT] Start:TestBeanIC.lookup()
12:18:12,890 INFO [STDOUT] Exception:javax.naming.NameNotFoundException: jms not bound
12:18:12,890 INFO [STDOUT] End:TestBeanIC.lookup()
12:18:12,890 INFO [STDOUT] End:TestBeanIC.init()
12:18:13,062 INFO [STDOUT] Start:TestBeanIC.method1()
12:18:13,062 INFO [STDOUT] Start:TestBeanIC.lookup()
12:18:13,062 INFO [STDOUT] Exception:javax.naming.NameNotFoundException: jms not bound
12:18:13,062 INFO [STDOUT] End:TestBeanIC.lookup()
12:18:13,062 INFO [STDOUT] End:TestBeanIC.method1()
12:18:13,156 INFO [STDOUT] Start:TestBeanIC.method2()
12:18:13,156 INFO [STDOUT] Start:TestBeanIC.lookup()
12:18:13,156 INFO [STDOUT] Exception:javax.naming.NameNotFoundException: jms not bound
12:18:13,156 INFO [STDOUT] End:TestBeanIC.lookup()
12:18:13,156 INFO [STDOUT] End:TestBeanIC.method2()
12:21:44,750 INFO [STDOUT] Start:TestBeanIC.destroy()
12:21:44,750 INFO [STDOUT] Start:TestBeanIC.lookup()
12:21:44,765 INFO [STDOUT] Exception:javax.naming.NameNotFoundException: env not bound
12:21:44,765 INFO [STDOUT] End:TestBeanIC.lookup()
12:21:44,765 INFO [STDOUT] End:TestBeanIC.destroy()
12:21:44,765 INFO [EJBContainer] STOPPED
EJB: com.ejb3inaction.actionbazaar.test.TestBeanIC ejbName: TestBeanIC
A related question:
ETS:
Is this statement correct?
Q) All Session beans can retreive resource manager references in ejbCreate().
Answer: Only stateful session beans can do so in their ejbCreate(). Stateless session
beans can do so only in their business methods becuase ejbCreate() and ejbRemove()
do not have any meaningful client transaction context and security context.
My questions:
a) What is ejbCreate() ? How and when is it invoked for stateless and stateful session bean? Is this from EJB 2.1
b) What do you mean by retreive resource manager references?
Can someone explain me with some code.