• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Primary key and setter method

 
Bob Walker Jr
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an entity bean CustomerBean. It has a customerid String field which is also its primary key. Can I have a setCustomerId(String id) method in the remote interface of this bean?
I couldn't find anything in the spec that restricts this. If I am able to change the customerid (thereby changing the primary key), does it not amount to changing the identity of the entity bean? It should not be allowed, right?
Any thoughts please?
 
Andrew Perepelytsya
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This method will be used to set the id in ejbCreate() method. You don't have to expose it in the interface. Again, it's only a 'by-contract' rule, so technically nothing will stop you if you decide for some weird reason to do it.
 
Saurabh Banerjee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
section 10.3.5 of EJB specs specify that If the Bean Provider attempts to reset a primary key value, the container must throw the
java.lang.IllegalStateException. (container managed persistence)
 
Bob Walker Jr
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info, Saurabh. The spec also says that the remote interface should not expose the set accessor methods of the primary key fields. So that makes sense now.
thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic