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.
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 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.
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>
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 ]
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop