I understand that having both a local and remote interface is rare. I have heard others on this site say that they could not imagine a reason for having both.
Supposing there are two entity beans and they have a bi directional CMR. Each bean would have to have a local interface for the other to access it through. Of course, at least one of the beans will need a remote interface for clients to access it through. So it seems that at least in this case having both interfaces would be required.
So what's the story? Are bi directional CMRs rare?
Why do you soppose the designers of EJB made it so that entity beans in a CMR must use local interfaces to access each other?
What would happen if I wrote an accessor that was part of a CMR to lookup and return the remote interface? i.e. AccountBean and TransactionBean have a CMR. Suppose in AccountBean.getTransaction() I lookup the remote home for TransactionBean and call findByPrimaryKey on it, returning the results to the client. What would happen? Could I do this without declaring a CMR? If so why have CMRs?
Of course, at least one of the beans will need a remote interface for clients to access it through. So it seems that at least in this case having both interfaces would be required.
Not really, you'll probably be accessing this CMP (and it's CMR fields) through a session fa�ade, wich means that you don't need at all a remote interface (as the session beans will be in the same JVM).
Suppose in AccountBean.getTransaction() I lookup the remote
No. You can't do this. We can't write the code for getTransaction() CMR method in our bean. It is managed by the container and it doesn't allow us writing that code. So, it returns Local Interface objects always.
Also, your view is correct that at some point you might need both the interfaces for Beans but usually that would go against "Session Facade" design pattern which protects "direct access to Entity beans". So what you have usually is,
1. Remote interface for Session bean (may be local as well if there are other session beans accessing this session bean) 2. Local interface for Entity beans 3. Session beans wraps access to entity beans and returns DTO (Data Transfer Objects/Value Objects) to the web tier..
I hope this helps. Maulin
It runs on an internal combustion engine. This ad does not:
Free, earth friendly heat - from the CodeRanch trailboss