Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMP relationship question

 
Prakash Krishnamurthy
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question from the mock test for IBM 484, altough the question is clear to me, i dont agree with the choices given. Any suggestions on what the answer could be.
A container-managed persistence (CMP) bean A has a one-to-many container-managed relationship (CMR) with another container-managed persistence (CMP) bean B. Select the interface that will expose the methods related to this relationship. (choose one)

A. The local interface of bean A.

B. The local home interface of bean A.

C. The remote interface of bean A.

D. The home interface of bean A.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Prakash Krishnamurthy:
This is a question from the mock test for IBM 484, altough the question is clear to me, i dont agree with the choices given. Any suggestions on what the answer could be.
A container-managed persistence (CMP) bean A has a one-to-many container-managed relationship (CMR) with another container-managed persistence (CMP) bean B. Select the interface that will expose the methods related to this relationship. (choose one)

A. The local interface of bean A.

B. The local home interface of bean A.

C. The remote interface of bean A.

D. The home interface of bean A.

Homes aren't involved in relationships -- how could they be? So thattakes out B and D and leaves either the remote or local interfaces.
I quote from the EJB 2.0 spec, section 10.3.2:
"Container-managed relationships can exist only among entity beans within the same local relationship scope, as defined by the relationships element in the deployment descriptor. Container-managed relationships are defined in terms of the local interfaces of the related beans."
And on the page prior to that:
"The accessor methods for the container-managed relationship fields must not be exposed in the remote interface of an entity bean."
So, that takes out C, leaving A. Now, I agree that if the relationship is bidirectional that there COULD be methods on bean B as well. However, it's straightforward to figure out which of the answers on the quiz is (certainly) correct.
Kyle
 
Prakash Krishnamurthy
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Container-managed relationships are defined in terms of the local interfaces of the related beans

Can you tell me why? I thought that the CMR relationships were only specified in the deployment descriptor. Why should be Local Interface expose the methods?
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why should be Local Interface expose the methods?

If methods are not exposed how will the relation work ?
 
Prakash Krishnamurthy
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If methods are not exposed how will the relation work ?

Pradeep,
You are right. I do understand that you need to expose methods for the relation to work. But I was wondering why just the Local Interface and NOT the remote or HOme. For the Home Interface not being among the contender maybe I could say that the Home Interface just has Finder and Create methods and other Bean method declaration go into the Remote/Local Interface. But why NOT remote interface is my question?
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "why" of why not Remote interfaces has to do with how CMP is implemented. The reason that it's restricted to local interfaces is that the vendors need to put in specific optimizations to make CMR fast enough to be useful. For instance, vendors want to be able to do "path optimizations" that may implement queries as joins. So, for instance, if you have a one-to-one relationship between a person and an address, you should be able to do a join of the person and address tables and then only have one SQL select in the finder method of person, rather than having to do a SQL call for each address as you ask each person for their address.
There are other caching strategies that the vendors can use as well, but these only apply if both ends are in the same JVM. You can't cache across JVM's very well.
Kyle
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic