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.
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.
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,
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
I think it is, but what do you say?