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 class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Primary Key class?" Watch "Primary Key class?" New topic
Author

Primary Key class?

Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
I was reading on p333 and it mentions a "primary key class must be serializable and public". Where is this primary key class defined/shown in the book? and why must it be public and serializable?
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Where is this primary key class defined/shown in the book?

Which book ?

and why must it be public and serializable?

Actually, the EJB 2.1 spec says that the primary key class should be public (10.6.13 and 10.8.2) but it doesn't mention that it should be serializable, only that the class should be a legal value type in RMI-IIOP (9.8), which implies that it should be Serializable.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
Valentin thansk for answering my second second quesry. The book Im talking about is The HFEJB. I was thinking that an example of the primary key class would be shown somewhere but I guess its not.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
There is one example of a compound primary key class in chapter 10 of RMH's Enterprise Java Beans book.

Here it is:
Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
Hi Valentin,
Thanks for your response, but Im afraid I must trouble you once again. Could you please explain me why we have the equals and hashcode method defined in the primary key class?. im sort of lost of the whole what the role of the primary key class is in the scheme of things.
Rajan Murugan
Ranch Hand

Joined: Jun 24, 2006
Posts: 182
you would go in for primary key class if your primary key (the key with which you identify your entity uniquely) is made up from more than one field of the table or tables (in case the primary key fields are from different tables).

hashCode is more importantly used in storing into collections and other similar purposes where hashcode may be of use.

equals is to check if two keys are same so that we may know if two entities are equal.

go through the code given it will make things more clear and some of the stuff will be self explanatory


With Regards,<br /> Rajan<br />"Java Rocks"
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Originally posted by Amitabha Batranab:
Hi Valentin,
Thanks for your response, but Im afraid I must trouble you once again. Could you please explain me why we have the equals and hashcode method defined in the primary key class?. im sort of lost of the whole what the role of the primary key class is in the scheme of things.


No problem. If you read the sections I mentioned, you'll see that it is mandatory for the primary key class to override equals() and hashcode().
Rajan Murugan
Ranch Hand

Joined: Jun 24, 2006
Posts: 182
hi valentin,

Can you point out situations where the container/stub/client may be making use of hashCode() and equals().this is wrt Entity beans especially.
 
jQuery in Action, 2nd edition
 
subject: Primary Key class?