aspose file tools*
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
Author

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.

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

Rahul Juneja
ThoughtClicks - http://techlabs.thoughtclicks.com
sai Narayan
Greenhorn

Joined: Aug 16, 2004
Posts: 21
Hi!
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:


<entity>
...
<prim-key-class>java.lang.String</prim-key-class>
...
<primkey-field>userName</primkey-field>
...
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:


<entity>
...
<prim-key-class>com.mypath.MyBeanPK</prim-key-class>
...


Good luck for yourself.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why EJB require Primary key class