我试图将远程句柄持久化为有状态EJB3.0 bean。该bean的接口已定义:
@Remote public interface Hello extends Serializable { Handle getHandle(); void sayHello(); }
实现是:
@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"); } }
根据EJB Spec,那应该抓住我一个可序列化的句柄。但是我得到了:
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
我不确定我理解我做错了什么…所有有状态的bean应该具有可序列化的句柄。在EJB3.0中是否有“正确”的方法来获取可序列化的句柄?
getEJBObject不适用于EJB 3.0编程模型。您将需要使用@RemoteHome并实现EJBHome / EJBObject。