Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why EJB require Primary key class

 
Rahul Juneja
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
sai Narayan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
Hibernate IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic