• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

CMRs, basic design questions

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still trying to get my head around EJB.

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?

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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).

I just answered a similar question
https://coderanch.com/t/314071/EJB-JEE/java/CMR-local-interface
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just complementing....

I think you're missing some concepts, CMRs are totally needed! You can make an analogy with Foreign Keys in your database, what can we do without them?

I'm also learning J2EE and i know sometimes things are not clear, when it happens it's good to re-read some stuff till you actually understand it.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi T Rob,

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
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic