Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Accessor for PK Class

Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read many EJB books which all says PK class need to have getter methods for the PK fields that it contains. However, I searched thru the spec and could not find such requirement.

Can anyone point me to the right place in the spec which makes this requirement? I just scanned thru the few sections of the spec related the PK but could not find it. I just wonder if this info is hidden somewhere else.
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alec,

I can only find the following about PrimaryKey�s related to your question in the spec on page 203

10.8.2 Primary key that maps to multiple fields in the entity bean class
The primary key class must be public, and must have a public constructor with no parameters.

All fields in the primary key class must be declared as public.

The names of the fields in the primary key class must be a subset of the names of the container-managed fields.
(This allows the container to extract the primary key fields from an instance�s container-managed
fields, and vice versa.)

As I read it the bean provider does not have to supply setter and getters for the pk fields.
The only requirement is that the pk fields of the PrimaryKey class are public and that they match the names of container-managed persistent fields.

This also seems to be how the JBoss 4.0 developers have read the spec. JBoss does not expect getter and setters on primary keys. JBoss only verifies that the fields are public, have matching names with the container-managed persistent fields and that the hashCode and equals are implemented correctly and it will throw a run time error if the PrimaryKey does not have a default constructor with no arguments.

Kind regards
I am going to test your electrical conductivity with this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic