Session beans as Facade to entity beans

Discussions

EJB design: Session beans as Facade to entity beans

  1. Session beans as Facade to entity beans (1 messages)

    Hi,

    it seems to be commonly agreed that clients should not directly access entity beans, but use session beans as Facade (=design pattern). This works fine as long as the entity beans are accessed via "bulk accessors" (aka value
    objects). However, if the client needs to access the entities at a more fine-grained level, this approach gets soon unhandy, since all accessor methods of the entity bean have to be duplicated in the session bean.

    Let's say, the entity bean has some methods:

      public class MyEntity {
        public Vector getA();
        public Vector getB();
      }

    then, the session bean would have to look like this:

      public class MySession {
        public Vector getA(Object myEntityPrimaryKey) { ... }
        public Vector getB(Object myEntityPrimaryKey) { ... }
      }

    This means, all accessor methods of the entity bean have to be duplicated in the session bean, which I don't see much sense in (?).

    My questions:

    1) What's so bad about letting the clients access the entities directly?
    2) Using the Facade pattern, is there any better way of providing fine-grained access for the client?

    thx
    Heiko

    P.S. In my case I can't use bulk accessors effectively, since the entities contain some complex attributes like Vectors and tree-like structures, and I would end up sucking the entire database into my bulk accessor object if I tried to resolve all these attributes
  2. Each method call on a entity bean will be a remote call this can slow you down. If your getVecA() returned a collection it has to be another entity bean for it to give remotely available.