exam questions

Exam 1z0-895 All Questions

View all questions & answers for the 1z0-895 exam

Exam 1z0-895 topic 1 question 69 discussion

Actual exam question from Oracle's 1z0-895
Question #: 69
Topic #: 1
[All 1z0-895 Questions]

A developer writes a stateless session bean FooBean and uses its deployment descriptor to declare a local ejb dependency on a stateful session bean in the same ejb-jar.

Which environment annotation, when declared within the FooBean bean class, is equivalent to the ejb-local-ref shown above?

  • A. @EJB(beanName="BarBean") Private acme.Bar barRef;
  • B. @EJB(name="bar", beanName="BarBean") Private acme.Bar barRef;
  • C. @EJB(name="barRef", beanName="BarBean") Private acme.Bar bar;
  • D. @EJB(name="ejab/barRef", beanName="BarBean")
Show Suggested Answer Hide Answer
Suggested Answer: contributeC 🗳️
name is barRef
Example:
ejb-local-ref
share [gp] share [fb] share [tw]

Via annotation -
Usable by EJB, Interceptor, Servlet, Filter, or Listener
package org.superbiz.refs;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
@Stateless
@EJB(name = "myFooEjb", beanInterface = FooLocal.class)
public class MyEjbLocalRefBean implements MyBeanInterface {
@EJB
private BarLocal myBarEjb;
public void someBusinessMethod() throws Exception {
if (myBarEjb == null) throw new NullPointerException("myBarEjb not injected");
// Both can be looked up from JNDI as well
InitialContext context = new InitialContext();
FooLocal fooLocal = (FooLocal) context.lookup("java:comp/env/myFooEjb");
BarLocal barLocal = (BarLocal) context.lookup("java:comp/env/org.superbiz.refs.MyEjbLocalRefBean/myBarEjb");
}
}

Via xml -
The above @EJB annotation usage is 100% equivalent to the following xml.
<ejb-local-ref>
<ejb-ref-name>myFooEjb</ejb-ref-name>
<local>org.superbiz.refs.FooLocal</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>org.superbiz.refs.MyEjbLocalRefBean/myBarEjb</ejb-ref-name>
<local>org.superbiz.refs.BarLocal</local>
<injection-target>
<injection-target-class>org.superbiz.refs.MyEjbLocalRefBean</injection-target-class>
<injection-target-name>myBarEjb</injection-target-name>
</injection-target>
</ejb-local-ref>

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Currently there are no comments in this discussion, be the first to comment!
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...