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
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.
Eric is correct.. Even Head First EJB book says that the CMP cannot be created without a primary key
A Devoted Java Adherent
Joined: Sep 22, 2003
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
subject: Can CMP entity beans created without a Primary Key ?