• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ETS Question doubts

 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Hoo hoo hoo! Looks like we got a live one! Here, wave this tiny ad at it:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic