Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reg Prim key class

 
Giju George
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it a must that the primary key class SHOULD define getter and setter methods for all variables declared??.
The spec (10.8.2) doesn't say anything !!!
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Giju,

I think that you replied to your own question by yourself:

The spec (10.8.2) doesn't say anything !!!


It means that it's not mandatory for sure. But as "All fields in the primary key class must be declared as public.", even in the case you'd provide getters and setters, the Container wouldn't use them: given the spec, the Container will access the fields directly, using reflection.

Regards,

Phil.
 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For CMP, a primary key must be set by the end of ejbCreate() method. Although it is not required, the benefit of having the getter and setter methods to access a primiary is to allow bean provider to validate the primary key.
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,

I think your argument is questionable for design reasons (I mean that if you think of some business rules to be applied for validation, the persistence layer is not the right place). But it's not the point: you don't set the primary key yourself, the *Container* will do it for you. And as it won't call your setters anyway, any validation code you'd put in them would be useless by definition.

Regards,

Phil.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic