I'm looking for opinions on how to structure an outer Facade, friendly to Applets/JSPs, which ultimately manipulates Entity Beans. Here is the proposed architecture:
Outer Session Bean Facade -> Inner Session Bean Facade -> Entity Beans
This much is given: the Entity Beans are CMP and TX_REQUIRED, and are intended only to be manipulated by the Inner Session Facade. The methods on the Inner Session Facade have arguments and return values which all rest in EJB Space (that is, where Entity Beans are passed and returned, they are passed 'directly' as implementers of javax.ejb.EJBObject rather than passing a placeholder like a Handle or a Primary Key).
Where I want opinions is on structuring the Outer Session Facade's methods. Where I need to represent Entity Beans for method parameters or return values, I can't use javax.ejb.EJBObject implementers because I need them to be able to serialize. I see two options:
- pass javax.ejb.Handle instances.
- pass primary key instances.
I see the advantage of passing Handles to be that the front end can only hold one if it actually corresponds to an existing Entity, and that when the Handle gets passed to the back end as a parameter there may be some savings when the Handle has to be transformed into its javax.ejb.EJBObject counterpart. The disadvantage is that Handles are larger when serialized than primary keys are.
The advantage of passing Primary Keys instead is that they are type-safe and leaner on the wire (smaller when serialized). They are also easier for novice front-end developers to conceptualize. On the other hand, they invite the front-end to toy illegitimately with the inner values of the primary keys. For example, the front-end could instantiate a primary key which doesn't correspond to an actual Entity Bean, and relationships between Entity Beans could be manipulated in a non-object oriented way by direct getter/setter methods for foreign key values. Also, whenever a primary key is intercepted by the inner session facade, the appropriate findByPrimaryKey method must be called rather than just handle's getEJBObject(). I just don't see that the front end should ever really concern itself with the internal value of the primary key for any Entity Bean.
Based on my reasons above, I lean toward making the outer session facade pass and receive Handles as placeholders for Entity Beans, rather than primary keys. What do others think about this?
Charles May
Technology Delivery Department (TDD)
Mellon Financial Corporation
Pittsburgh, PA
