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.
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.