title: Stateful EJB in business tier used in the conversation scope of the web tier
body: <p>I have an enterprise application with (at least) a web tier (UI only) and a service tier. In the service layer is all the business logic and the current conversation state implemented as <code>@Stateful @LocalBean</code> EJBs (no CDI).</p>
  
  <p>This is somewhat similar to a <code>@SessionScoped</code> bean in terms of CDI, right?</p>
  
  <p>So, here's the issue:
  I have a long running conversation in the web tier (<code>@Named @ConversationScoped</code>) and want to access the Stateful EJB. The EJB should be accessed in different controllers (beans) of this conversation. I can't do it like this: <code>@EJB</code> because it would be a different instance of the particular EJB type. I have to save the reference to the EJB somehow. This is my current solution:</p>
  
  <pre><code>@EJB
  private MyEJB _myEJB; // a stateful EJB
  
  @Produces
  @Builder // custom quallifier
  @ConversationScoped
  public MyEJB produceMyEJB() {
      return _myEJB;
  }
  </code></pre>
  
  <p>Now I can access the same instance of the stateful EJB in each of the conversation scoped controllers like this <code>@Inject @Builder MyEJB _myEJB</code>.</p>
  
  <p>It works, most of the time. But in some long running tests this reference is null and I don't know why.</p>
  
  <p>I get this stack trace in the server.log of Glassfish:</p>
  
  <pre><code>javax.ejb.NoSuchObjectLocalException: The EJB does not exist. session-key:
  907f0200001f-ffffffffc3388fbb-761
  </code></pre>
  
  <p>and/or</p>
  
  <pre><code>Cannot load from  BACKUPSTORE FOR Key: &lt;907f0200001f-ffffffffc3388fbb-761&gt;
  </code></pre>
  
  <p>Do You have any ideas why this happens? Thanks for help and sorry for my bad English.</p>