EJB design: Storing a reference to a stateful session bean in HttpSession

  1. Would it be considered poor design to store a reference to a stateful session bean in the HttpSession object? Values in the session bean are client specific and I need to be able to get to them from a servlet/jsp.

  2. andy,

    its perfectly ok. the top layer can be aware of its underlying layer but not vice-versa.
  3. It's fine but:

    1) The session could become "stale" if the server it points to dies. You have to handle that problem and relook up the session bean from it's home interface (this assumes a stateful session bean, for stateless it'll happen pretty much 'by magic' :-))

    2) If your server storing the HttpSession objects does not replicate the session between itself and other servers in the cluster, then when the server holding the session dies, so does your reference to the EJB.

    (2) is all about how your server product works. (1) can be made easier by holding state in some form of memento object in the session, and also holding a handle to a _stateless_ session bean, which you pass the memento to when you call it. That will make your fault tolerance life a bit easier, and also lets you store the state in a more lightweight value object which you might want to use elsewhere.