Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can setter methods exist for primary key?

 
trivikram Kumar
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the answer is no then the sentence:

Setter methods for fields associated with the primary key must not be associated through a client view is correct or wrong??

I am confused after seeeing this as termed correct in HFEJB final mock (46th question).
Could someone please explain this....
 
KasiMurugan Ramasamy
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
S javainn

If you provide the setter methods in client view, assume the client trying to change the primary key means, for the updation purpose( i mean Bean to DB) the container couldn't find the primary for the bean, it resultant that a container would throw an exception.

So the conclusion is you can keep the setter methods in client view, it never disturb compilation and deployment process, but it would throw an exception while you calling in the client view.

So never disclosure your primary key fileds setter methods. It is not encouraged. Thats all.

I feel, you will get me.
 
chao cai
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes,
like the ejbCreate must return null,not need to return the primary key.
container will set the primary key
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.
Setter methods for fields associated with the primary key must not be associated through a client view is correct or wrong



EJB specs page 130

Once the primary key for an entity bean has been set, the Bean Provider must not attempt to change it by use of set accessor methods on the primary key cmp-fields. The Bean Provider should therefore not expose the set accessor methods for the primary key cmp-fields in the component interface of the entity bean.


Although it won;t thown an exception if you expose the setter method but it is not a good practice.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic