Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:


?
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vince Hon
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The EJB specifications mandate that all the fields that made up the compound primary key class had to be declared public (pg 203).
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic