posted 20 years ago
OK, folks, I'll try to expose my view of why entity beans must expose a local interface in order to participate in container-managed relationships.
As Marcelo said, one of the reasons is for performance purposes, as it is much quicker to perform a local call in the same JVM on an object reference instead of a remote method invocation through RMI.
BUT, the rationale for this is that the relationships between two entity beans must be specified as an abstract persistence schema in the deployment descriptor where the <relationship-role-source> elements must contain the name of en entity bean declared in the same descriptor. For this reason, it is mandatory that entity beans with container-managed relationships are specified in the same deployment descriptor, and are thus deployed together in the same container. Assuming this, it does not make much sense to require that collocated entity beans communicate with each other by using the network loopback. A huge performance penalty would incur.
As an analogy, consider the following. Imagine that you want to make a recipe and you need some ingredients like milk, butter, flour and sugar. Instead of buying all items at once, you drive to the supermarket for buying each single item. The scenario would look as follows:
You are in your kitchen and you see on the recipe that you need a bottle of milk. You dress up, you get in your car, you drive to the supermarket, you get in the shop, you find the milk, you stay in line, you pay, you get in your car, you drive back, you get out of car, you get back in your kitchen and add the milk to your recipe. Then, you need to add some butter and you repeat the exact same steps again. And so on with the other ingredients. Wouldn't it be easier to go once to the supermarket, buy everything you need and put them in the fridge or wherever, and then just open it to get what you need?
The analogies are the following:
recipe: business process ingredients: beans you need to carry out the processget in the car: RMI marshallingfind the product: retrieve the correct beanget out of the car: RMI unmarshallingincorporate the ingredient: invoke some method on the beanyour kitchen (in the case you have to go to the supermarket): client application or session beanyour kitchen (in the case you already have everything in the fridge): the EJB containergoing to the supermarket: remote callsopening the fridge and getting something: local call
[ April 08, 2004: Message edited by: Valentin Crettaz ]