• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return value of ejbCreate() for bmp/cmp

 
Denis Wang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got confilicting information as to the above issue:
1) CMP must return null for ejbCreate()
2) CMP/BMP follows the same signature to enalbe switch or subclass
Which is correct? especially SCEA correct?
Thanks.
Denis
 
E. Messing
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CMP must return null - As of J2EE spec.
 
Denis Wang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which verion of ejb spec are you talking about?
I am looking at Mastering Enterprise JavaBeans. The code example uses pk ejbCreate() for SFSB.
Denis
 
Bharat Ruparel
Ranch Hand
Posts: 493
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of the "nasty" ones!
Entity Beans - The return value of the ejbCreate method for a CMP bean should be the PK (Class) as in:
PK ejbCreate(...) {
.
.
return null;
}
See the return null statement above? That means for the Container Managed Persistent, the container will "make" the primary-key for you, you don't have to explicitly return it. However, the method signature, i.e., PK ejbCreate(...), must have its return type as PK. In the Bean Managed Persistence, you will explicitly return the primary key value instead of returning null.
Dennis, the example that you have from Mastering Enterprise JavaBeans which says:
pk ejbCreate() for SFSB is plain wrong. Stateful session beans do not return pk, they do not have primary key, they return "void" in the ejbCreate method.
Hope this helps.
Regards.
Bharat
p.s. If you are a bit unsure of yourself in the EJB area, consider SCBCD. I was more or less forced to memorize the "Bean" law like a lawyer. It is a spec full of exceptions and sometimes they don't make much sense either, but a law is a law and that is how we have to approach it.
 
Denis Wang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. I got a free conslutation from a certified EJB lawyer!
By the way, the example from Mastering Enterprise JavaBeans is
pk ejbCreate() { // for <<<CMP Entity Bean>>>
...
return pk;
}
<<<SFSB>>> is my own mistake.
Thanks a lot!
Denis
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic