File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes question about dependent injection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "question about dependent injection" Watch "question about dependent injection" New topic
Author

question about dependent injection

vitesse wei
Ranch Hand

Joined: Sep 07, 2007
Posts: 100
mock question:
Given a stateless session bean with container-managed transaction demarcation, from which two
methods can a developer access another enterprise bean? (Choose two.)
A. bean constructor
B. Timeout callback method
C. PreDestroy lifecycle callback method
D. PostConstruct lifecycle callback method
E. business method from the business interface

I think we can do DI in any of these methods,but given answer is B,E,anyone please clear for me.


SCJP 5.0<br />SCWCD1.4<br />SCBCD5
Benoît de Chateauvieux
Ranch Hand

Joined: Aug 10, 2007
Posts: 183
Hi vitesse WEI,

For me, the most important phrase to understand this part of the specs is in 4.5.2:
Accessing resource managers, enterprise beans, and the EntityManager is disallowed in the session bean methods for which the container does not have a meaningful transaction context and/or client security context.


So:

A- An EJB Constructor doesn't have meaningful transaction context nor client security context. In his constructor, an EJB can't access anything.

B- The specs (18.2.5) says:
The timeout callback method is typically has transaction attribute REQUIRED or REQUIRES_NEW. If the transaction is rolled back, the container retries the timeout.

So it can access other EJB.

C and D- PostConstruct and PreDestroy of Stateful SB can access other EJB
but the same lifecycle callback, when implemented on a Stateless SB, can't.
I think it's because:
- In the case of Stateful SB, the creation and destruction result from an action of the user.
- In the case of Stateless SB, the creation and destruction result from a decision of the container (Pool Management).

E- A business method has meaningful transaction context or client security context.


Those two tables (in 4.4.1 and 4.5.2) are very important for the exam.
But the understanding is not very easy.

Hope it helps,

Beno�t


SCJP5 | SCBCD5 | SCEA5 Part 1
vitesse wei
Ranch Hand

Joined: Sep 07, 2007
Posts: 100
thanks,Beno�t,that really help me.
Marcin Faryna
Greenhorn

Joined: Jul 16, 2009
Posts: 15
Hello everyone, very helpful answer Benoît but i have some doubts about the spec int this matter. On the page 79 (JSR 220) there is a table describing "Operations Allowed in the Methods of a Stateful Session Bean". There are PostConstruct, Pre-Destroy, PrePassivate, PostActivate lifecycle methods on the left and on the right access to Resource manager, Enterprise bean and others described as allowed. Isn't it conflicting with:

Accessing resource managers and enterprise beans is disallowed in the session bean methods
for which the container does not have a meaningful transaction context and/or client security
context.


I think it is, but what do you say?


SCJP 6, SCBCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about dependent injection