• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Why EJB require Primary key class

 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 120
IntelliJ IDE Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
...

 
reply
    Bookmark Topic Watch Topic
  • New Topic