aspose file tools*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Can CMP entity beans created without a Primary Key ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Can CMP entity beans created without a Primary Key ?" Watch "Can CMP entity beans created without a Primary Key ?" New topic
Author

Can CMP entity beans created without a Primary Key ?

Francesco Marchioni
author
Ranch Hand

Joined: Sep 22, 2003
Posts: 191
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


WildFly 8 Administration Book - JBoss Tutorials
Erik Brakkee
Ranch Hand

Joined: Jun 21, 2004
Posts: 40
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


SCJP, SCJD, SCWCD, SCBCD
Arun Kumar Ilangovan
Ranch Hand

Joined: Apr 28, 2005
Posts: 44
Eric is correct.. Even Head First EJB book says that the CMP cannot be created without a primary key


A Devoted Java Adherent
Francesco Marchioni
author
Ranch Hand

Joined: Sep 22, 2003
Posts: 191
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can CMP entity beans created without a Primary Key ?