title: @EJB annotation null
body: <p>I'm trying to understand how @EJB(beanName="etc") works. I've tried to use it and when called stays null. I've read in other threads that I shouldn't be using a "new ClassNameEJB()" to initialize it. I am under the impression that using the @EJB annotation provides the initialization for the local private field. Here are my implementations:</p>
  
  <p>Bean Class:</p>
  
  <pre><code>@Stateless(name = "AsynchronousErrorLog")
  @TransactionManagement(TransactionManagementType.BEAN)
  public class AsynchronousErrorLogEJB {
  
  @PersistenceContext(unitName = "errorLog")
  EntityManager entityManager;
  @Resource
  private EJBContext context;
  private static final Logger LOG = Logger.getLogger(AsynchronousErrorLogEJB.class);
  
  
  /**
   * logError: method to store error within the database 
   * @param errorLog: log to be persisted to the database
   */
  @Asynchronous   
  public void logError(final ErrorLog errorLog) {
      try {
          LOG.debug("Entering logError");
          context.getUserTransaction().begin();
          entityManager.persist(errorLog);
          context.getUserTransaction().commit();
      } catch (final Exception e) {
          LOG.secureError("Exception while logging error during transaction", e);
          try {
              context.getUserTransaction().rollback();
          } catch (final Exception e1) {
              LOG.secureError("Could not rollback transaction", e1);
          }
      }
      LOG.debug("error logging complete.");
  }
  
  }
  </code></pre>
  
  <p>I have in a class a private @EJB field written as such:</p>
  
  <pre><code>@EJB(beanName="AsynchronousErrorLogEJB")
  private AsynchronousErrorLogEJB errorLogLocal;
  </code></pre>
  
  <p>which utilizes the EJB as such:</p>
  
  <pre><code>    try {
          ErrorLog eLog = new ErrorLog(e, ServerName.getServerName());
          errorLogLocal.logError(eLog);
      } catch (GeneralException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
  </code></pre>
  
  <p>I have the table structure for this EJB as such:</p>
  
  <pre><code>@Entity(name="ERROR_LOG")
  public class ErrorLog {
  
      @Id
      @Column(name="ERROR_LOG_ID")
      private String errorLogId;
      @Column(name="ERROR_MESSAGE")
      private String errorMessage;
      @Column(name="TIMESTAMP")
      private Date timeStamp;
      @Column(name="SERVER_NAME")
      private String serverName;
      @Column(name="STACK_TRACE")
      private String stackTrace;
  </code></pre>
  
  <p>when it gets to the errorLogLocal.logError, it passes right over it. When debugging in JBoss 9 the value for errorLogLocal is null. Is there a step I'm missing somewhere? Do I need to include some underlying structure in an xml file to the container? Do I have to use INitialContext.lookup in some instances or can I use @EJB notation without lookup?</p>
  
  <p>EDIT: I've added the necessary elements to my persistence.xml (under META-INF) file for the PersistenceContext. I'm not sure if its properly implemented but I followed along with a previous implementation:</p>
  
  <pre><code>    &lt;persistence-unit name="errorLog"&gt;
          &lt;non-jta-data-source&gt;java:/jdbc/STOMP&lt;/non-jta-data-source&gt;
          &lt;class&gt;com.ens.stomp.message.log.ErrorLog&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.archive.autodetection" value="false" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt; 
  </code></pre>