aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes CMP relationship question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "CMP relationship question" Watch "CMP relationship question" New topic
Author

CMP relationship question

Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
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

Joined: Aug 10, 2001
Posts: 3892
    
    5
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


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154

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

Joined: Feb 27, 2002
Posts: 8919

Why should be Local Interface expose the methods?

If methods are not exposed how will the relation work ?


Groovy
Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
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

Joined: Aug 10, 2001
Posts: 3892
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CMP relationship question