File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Primary key and setter method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » EJB Certification (SCBCD/OCPJBCD)
Reply Bookmark "Primary key and setter method" Watch "Primary key and setter method" New topic
Author

Primary key and setter method

Bob Walker Jr
Ranch Hand

Joined: Jun 02, 2003
Posts: 46
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

Joined: Aug 21, 2002
Posts: 93
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

Joined: Nov 13, 2001
Posts: 5
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

Joined: Jun 02, 2003
Posts: 46
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.
 
 
subject: Primary key and setter method
 
Threads others viewed
CMR entity beans and primary key.
Entity bean with composite key
return type ejbCreate CMP
Choose primary key for CMR entity beans
Some Questions from Mock Exams
MyEclipse, The Clear Choice