Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ETS Question doubts

 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
LakshmiNarayana Kodali
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the Question 1 which you posted regarding lookup() method,

the answer is a,b,c.

In the lookup() method, 2 components are retrieved.
1. JMS resource using JNDI lookup (i,e Resource access)
2. Enterprise Bean access.

Both of these 2 things can be done using business method and also lifecycle callback methods.

So lookup() can be
a) It can be a business method
b) It can be a @PostConstruct method (It is lifecycle callback method)
c) It can be a @Remove method (It is also a business method in Stateful Bean)


These are the following things which can be done using both business methods and lifecycle callback methods.

1. SessionContext methods: getBusinessObject, getEJBHome, getEJBLocalHome, getCallerPrincipal, isCallerInRole, getEJBObject, getEJBLocalObject,
lookup
2. JNDI access to java:comp/env
3. Resource manager access
4. Enterprise bean access
5. EntityManagerFactory access
6. EntityManager access

-------------------------------------
LakshmiNarayana Kodali
SCJP 5(98%), SCWCD(100%), SCBCD in progress
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic