title: EJB3.0 Serializing a handle to a Stateful Bean
body: <p>I'm attempting to persist the remote handle to a Stateful EJB3.0 bean. This bean's interface is defined:</p>
  
  <pre><code>@Remote
  public interface Hello extends Serializable {
       Handle getHandle();
       void sayHello();
  }
  </code></pre>
  
  <p>The implementation is:</p>
  
  <pre><code>@Stateful
  @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  public class HelloBean implements Hello {
  
      @Resource
      private SessionContext ctx;
  
      @Override
      public Handle getHandle() {
            try {
                return ctx.getEJBObject().getHandle();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
      }
  
      @Override
      public Handle sayHello() {
          System.out.println("hello");
      }
  }
  </code></pre>
  
  <p>According to the EJB Spec, that should grab me a serializable handle. But instead I get:</p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: EJBObject not available
      at com.sun.ejb.containers.EJBContextImpl.getEJBObject(EJBContextImpl.java:328)
      at com.zzz.zzz.HelloBean.getHandle(WorkHolderBean.java:125)
      ... 75 more
  </code></pre>
  
  <p>I'm not sure I understand what I did wrong... All Stateful beans should have a serializable handle. Is there a 'correct' way of obtaining the serializable handle in EJB3.0?</p>