• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Primary Key class?

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Amit Batra
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic