This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Primary Key Class - Public field or public getter/setter ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Primary Key Class - Public field or public getter/setter ?" Watch "Primary Key Class - Public field or public getter/setter ?" New topic
Author

Primary Key Class - Public field or public getter/setter ?

Vince Hon
Ranch Hand

Joined: Feb 11, 2003
Posts: 117
On HFB p. 333 - "Rules for Primary Keys"

point 4:
A compound key class must be made up of fields that are defined as persistent fields in the bean class.The fields in the bean class must have upblic accessor methods


This only say "Compound key class" needs public accessor methods.
How about "Single key class" ?

refer to p. 370 q. 13

What's true about an CMP entity bean's primary key ?

C. All fields in the primary key class must be declared public.
//opt C is correct.

Does it mean that Single key class is not required to have public accessor ?

can I:


?


Vince Hon<br /> <br />SCJP 1.4 | SCWCD | SCBCD <br /><a href="http://vincehon.homeip.net:8000/VJW" target="_blank" rel="nofollow">http://vincehon.homeip.net:8000/VJW</a>
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
When we talk about single field primary keys, we're usually refering to objects such as String, Integer, Long, Short, Character, etc. You usually won't be defining a custom class to contain just a single String since you've the option of declaring it as your primary key.



This is taken from the DTD file. The first example would be our single field primary key & the second being the multiple field primary key. Your entity bean would usually contains other fields & your compound primary key class should be made up of some of these fields.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Vince Hon
Ranch Hand

Joined: Feb 11, 2003
Posts: 117
Thx Chengwai. I am clear about the single field primary class now.

However, for compound key, here is the question.


refer to p. 370 q. 13

What's true about an CMP entity bean's primary key ?

C. All fields in the primary key class must be declared public.
//opt C is correct


Why option C is correct ?
As I know, "Compound key class" needs only "public accessor methods" (the fields can be private).

Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
The EJB specifications mandate that all the fields that made up the compound primary key class had to be declared public (pg 203).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Primary Key Class - Public field or public getter/setter ?
 
Similar Threads
how can i specify composite primary key in CMP
HF Pg 333 Regarding the Primary Key Class
Primary key and reflection
set accessor method for PK
needs clerification from chapter 6 Entity Bean Synchronization