Forums Register Login

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

+Pie Number of slices to send: Send
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:


?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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).

+Pie Number of slices to send: Send
The EJB specifications mandate that all the fields that made up the compound primary key class had to be declared public (pg 203).
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1016 times.
Similar Threads
HF Pg 333 Regarding the Primary Key Class
Primary key and reflection
how can i specify composite primary key in CMP
needs clerification from chapter 6 Entity Bean Synchronization
set accessor method for PK
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:50:23.