Aggregate Entity with entity-entity EJB relations is inelegant?

Hi,

Take a look at he Aggregate Entity Design Pattern. http://developer.java.sun.com/developer/restricted/patterns/AggregateEntity.html

In one portion it states "According to the EJB 2.0 specification, a dependent object is defined as follows:............" This means the authors were quite knowledgeable of EJB2.0 spec and whatever it is going to do to deal with entity-entity relationships. However, the still detest enity-entity relationships as:

".....

Impact on relationships

Direct mapping of an object model directly to an EJB model does not take into account the impact of relationships between the objects. The inter-object relationships are directly transformed into inter-entity bean relationships. As a result, an entity bean might contain a reference to another entity bean (that is, the entity bean holds a remote reference to another entity bean). However, maintaining remote references to distributed objects involves different techniques and semantics than maintaining references to local objects. Besides increasing the complexity of the code, it reduces the flexibility because the entity bean must change if there are any changes in its relationships.

There is also no guarantee that the entity bean references to other entity beans remain valid over time. Such references are established dynamically using the entity's home object and the primary key for that entity bean instance. This implies a high maintenance overhead of reference validity checking for each such entity bean-to-entity bean reference.

...

...one way to model this (entity-entity) relationship is to store the dependent object entity bean's primary key in the coarse grained object. When the coarse-grained object needs to access the dependent object, it will result in an entity-to-entity invocation.

The sequence diagram for scenario is shown below. The Aggregate Entity uses the dependent object references to look up the required dependent entity beans. The dependent object in this case is a proxy to the dependent entity bean as shown.

...."

And the authors suggest in the end:

"While this may address the requirement of using a dependent entity bean from a parent entity bean, it is not an elegant solution. Instead, to avoid the complexity of designing and managing inter-entity relationships, consider using a session bean to help manage the relationships among entity beans. In our experience, we have found that the session faade pattern helps us to avoid this problem and to provide a better way of managing entity bean to entity bean relationships.

So, we recommend, that as a best practice, try and avoid entity-to-entity bean relationships."

Now I am in real trouble. I am unable to understand that when we talk of object model, no one is bothered about entity relationships, rather it is the only design choice for associated classes. However, when the same object model is converted to EJBs, (Please note that this is the case when there have to be two associated entity EJBs. If an object needs to be persistent but need not be accessed dierctly by the client, its made a simple dependent object and not a entity ejb. In whcih case, the object model does change while converting to EJBs)..why they say things like:

"The inter-object relationships are directly transformed into inter-entity bean relationships. As a result, an entity bean might contain a reference to another entity bean (that is, the entity bean holds a remote reference to another entity bean). However, maintaining remote references to distributed objects involves different techniques and semantics than maintaining references to local objects. ..-=-> //HERE: -> (I am lost) Besides increasing the complexity of the code, it reduces the flexibility because the entity bean must change if there are any changes in its relationships. There is also no guarantee that the entity bean references to other entity beans remain valid over time. Such references are established dynamically using the entity's home object and the primary key for that entity bean instance. This implies a high maintenance overhead of reference validity checking for each such entity bean-to-entity bean reference. " -> Why this thought is not the case with the simple object model?

Paying a terrrible price, I got hold of the book "Enterprise Java Performance" and in one section it states, that the ...MOST object oriented way of showing relationships between entity beans is to have a reference of one ejb in another.. i.e. the same as simple object model..? No one other the the J2EE DP or VisualAge docs has so far talked of this issue.. J2EE DP docs authors as mentioned above are quitee aware of EJB 2.0 ..but then why all this?

Regards,

Hasan

[4880 byte] By [meltwater] at [2007-9-26 18:09:22]
# 1

Please note that the authors are not talking of network traffic that has been solved by EJB 2.0, they are not talking of portability and persistence of entity EJB references, that also has been solved by EJB 2.0. In fact, they are giving a design guideline that has nothing to do with EJB 1.1. or 2.0.

Regards,

Hasan

meltwater at 2007-7-3 1:54:25 > top of Java-index,Other Topics,Patterns & OO Design...