Session bean calling another session bean


EJB programming & troubleshooting: Session bean calling another session bean

  1. Session bean calling another session bean (1 messages)

    Are there cases where it is a correct pattern for a session bean to call another session bean. The example I am thinking of is a Stateful session bean calling a Stateless session bean to perform a section of business logic. I know this is possible but is it advisable. If Session beans call each other isn't there a danger of circular dependencies and loopbacks?
  2. Hi Barry ,

    I do not see any reason why a Stateful bean calling a Stateless bean violate any patterns. The idea of stateless session beans are always to encapsulate a piece of business logic , while stateful ones can keep track of any required state on behalf of the client. Keeping state on stateful beans and ensuring cleanly separated business logic on stateless beans can result in a pretty reusable stateless beans.

    The reverse (stateless bean calling stateful bean) may not be true. Usually there is really no point doing stateless calling stateful.

    I do not think you need to worry about circular dependencies and loopbacks in session beans calling each other. This will not happen unless you *purposely* make it that way (in which case we can categorize this kind of interaction as re-entrance , which is not advised by the EJB spec).