title: Possible JNDI lookups within EJB container
body: <p>I'm going through the <a href="http://download.oracle.com/otndocs/jcp/ejb-3.1-pfd-oth-JSpec/" rel="nofollow">EJB 3.1 spec</a> and am trying to grasp the different possible ways a JNDI call can be made.</p>
  
  <p>You can do it using a <a href="http://docs.oracle.com/javaee/6/api/javax/ejb/SessionContext.html" rel="nofollow">SessionContext</a> and an <a href="http://docs.oracle.com/javase/6/docs/api/javax/naming/InitialContext.html" rel="nofollow">InitialContext</a> (or a self-created context based on the Initial- or SessionContext).
  Based on which you use the syntax differs, but I can't seem to find the logic behind it.</p>
  
  <p>So my question is: <strong>when can I use what syntax to use JNDI calls within an EJB container environment?</strong></p>
  
  <p>The rest of this question just serves as illustration of my point.</p>
  
  <p>For example, I believe this is always possible for a correctly injected <code>sessioncontext</code> or created <code>initialcontext</code>:</p>
  
  <pre><code>ctx.lookup(java:global[/&lt;app-name&gt;]/&lt;module-name&gt;/&lt;bean-name&gt;[!&lt;fully-qualified-interface-name&gt;])
  ctx.lookup(java:comp/env ...)
  // special ones like these
  ctx.lookup("java:comp/UserTransaction");
  ctx.lookup("java:comp/ORB");
  </code></pre>
  
  <p>Sometimes (only for session context?) this shorter version is possible:</p>
  
  <pre><code>ctx.lookup(&lt;bean-name&gt;);
  </code></pre>
  
  <p>What about in an <code>embedded environment</code>, can only <code>global</code> references be used?</p>