File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Why EJB require Primary key class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Why EJB require Primary key class" Watch "Why EJB require Primary key class" New topic

Why EJB require Primary key class

Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
Hi Guys !

Just wondering why the Primarykey class is required if the key type is String, which is itself serializable.

Rahul Juneja
[ August 24, 2004: Message edited by: Rahul Juneja ]

Rahul Juneja
ThoughtClicks -
sai Narayan

Joined: Aug 16, 2004
Posts: 21
Basically you need a custom Primary Key class when you have specified a
composite primary key(i.e when a combination of more than one field in a table is used as a primary key) for a table in the database.
for further reference see:-
Book Name:-Sams teach yourself J2EE in 21 days
chapter 6-Entity EJB's
Page 205.
Topic: Custom Primary Key Classes
Stan Sokolov
Ranch Hand

Joined: Apr 13, 2004
Posts: 120

Not sure, that this class is required. Wizards generate primary key class but as far as I know usage of primary key is recomented by not mandatory.

This is quote

In the EJB 1.1 specification, primary keys have been...
Shaun Childers, Jul 6, 2000
In the EJB 1.1 specification, primary keys have been defined as either simple or compound keys. Simple keys use a single field in the underlying datastore as a primary key, while compound keys use multiple fields. For simple primary keys, you don't need to wrap the field in a primary key class. This type of simple key is defined in the ejb-jar.xml deployment descriptor file:

For primary keys which map to primitive types, like int, the specification requires a primary key wrapper class. You can define these primay key types as compound primary keys. Note: Compound primary keys are used for multiple primary key fields as well as single primary key fields of primitive types. With compound primary keys, the EJB bean developer still has to define the primary key class. Compound primary keys are defined in the ejb-jar.xml file as follows:


Good luck for yourself.
I agree. Here's the link:
subject: Why EJB require Primary key class
It's not a secret anymore!