• 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

Can CMP entity beans created without a Primary Key ?

 
author
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe not, since findByPrimaryKey would return wrong
data...anyway I have found a different answer on
an exam test which I have bought just yesterday.
(I believe a typing mistake!).
Thanks
Francesco
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I just found this in the EJB 1.1 specs in section 9.2.9.

"The Bean Provider must specify a primary key class in the
deployment descriptor. The primary key type must be a legal
value type in RMI-IIOP"

In the deployment descriptor in the spec it says something slightly different:

For a BMP entity bean, you must specify the prim-key-class element in the deployment descriptor but not the primkey-field element. For a CMP entity bean, you must specify the primkey-field element and you may (but are not required to) specify the prim-key-class element.

I guess the reason for this is that with BMP there is no primary key field available so for read-only entities there are no ejbCreate() methods from which the primary key class can be inferred. For CMP beans, there is such a field regardless of the presence of ejbCreate methods so that the primary key type can always be inferred from there.


Cheers
Erik
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric is correct.. Even Head First EJB book says that the CMP cannot be created without a primary key
 
Francesco Marchioni
author
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
well thanks for your answers.
Actually the question can be seen from two points of view:
-the ejb side ( yes a CMP need a PK class or -at least- a prim-key-field )
-the db side ( does tha table actually requires a primary key ?)

The question I have found isn't clear about which one it means, but I believe that I can specify a prim-key-field even if in the DB I haven't
declared it as PK.

Maybe I'll write to the editor of the test to make it clear
Regards
Francesco
reply
    Bookmark Topic Watch Topic
  • New Topic