0 Replies Latest reply on Aug 2, 2006 11:10 AM by celer celer

    Session bean design for accessing tree based entity beans

    celer celer Newbie

      Hi, I am just getting started with EJB3, and I was working through an example and I can't seem to find a clean way to implement a session bean that access an entity bean which is recursive.

      So lets say our entity bean looks like so:

      public class TreeNode {
      long getId();
      void setId(long id);

      TreeNode getParent();
      void setParent(TreeNode parent);

      Collection getChildren();
      void setChildren(Collection children);

      And the tree is very large and deep, so using eager loading is not really what we want.

      I have tried a few designs of stateless session beans and it seems like all of them fail the principal of least astonishment - You can't use the getChildren() on the TreeNode after it has been serialized and passed to the client, because the children are lazy loaded. So instead your left having to implement an interface on the session bean for getting the children of a particular node.

      I haven't even touched on modifying the tree yet via the session bean :(

      Assuming that we needed a way for the client to examine and modify the tree what might the session bean interface look like? Would it be worth while making it a statefull session bean?