This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

ETS Question doubts

 
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.
 
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
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic