Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CMP scenario  RSS feed

 
Mike Cunningham
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is pulled from the Sample Test for IBM Test 287.
Here's the question:
An "account" CMP bean has a container-managed relationship to a "customer" CMP bean. The account table reflects a relationship with a foreign key relating to the customer table. The foreign key is declared with a "NOT NULL" constraint. When creating a new account for a customer the developer MUST:
A. set the customer in the ejbCreate method of the account bean
B. set the customer in the ejbPostCreate method of the account bean
C. set the account in the ejbPostCreate method of the customer bean
D. provide a local interface for the customer CMP entity bean
Select 2 answers and explain why.
 
Vinod John
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think B and D are correct,
A) The account bean may not know the primary key of customer bean.
B) According to spec the cmr fields should be set in ejbCreate.
C) is not a must because the customer bean can be created independent of the account bean.
D) is must correct bcos cmr only uses Local interfaces.
 
I Sahni
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Think A and C are the correct answers. As a insert will take place after ejbCreate so we have to associate customer with accout otherwise we will get a null pointer exception. Other way is to associate account in ejbPostcreate of Customer because we can create a Customer without getting a NP Exception.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A is wrong because setting CMR fields is prohibited in ejbCreate() <*1>
B is correct because CMR fields should be set in ejbPostCreate() <*1>
C is wrong because the account bean was not mentioned to have a local interface (?) <*2>
D is correct because CMR requires a local interface <*2>

<*1> EJB 2.0 spec, chapter 10.5.2, page 171
<*2> EJB 2.0 spec, chapter 5.4, page 54
 
Vinod John
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vinod John:
B) According to spec the cmr fields should be set in ejbCreate.

I should have been
"According to spec the cmr fields should be set in ejbPostCreate."
Sorry I typed it wrong
But on a second thought A could be more appropriate than be B(though the spec is on the contrary. As the foreign key is a NOT NULL column, so there is a chance of getting a constraint violation (if you don't set the column to be defererable in the database) ... If this is a Sun certification B is a better answer, but for pratical purpose A could be better ???
[ July 24, 2003: Message edited by: Vinod John ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!