Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ejbCreate() method return

 
Marcos Urata
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does the ejbCreate() method (when working with CMP) returns NULL??

I understand that it might be because the bean is still in process of an "insertion" on the database for example, so the bean�s PK might have not been generated yet. If that is true, why is the signature of the ejbCreate isn�t like the ejbPostCreate method that has a VOID return.

Thanks
Marcos
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason isn't immediately apparent as BMP entity beans are not covered in the exam.

Section 12.2.3 of the EJB 2.0 spec more or less states that the ejbCreate of a BMP bean has to return the primary key object - i.e. it actually returns something. This is when a BMP bean hands over the (new) primary key to the container.

Section 10.5.2 then (in a footnote) states that the ejbCreate method of a CMP bean still has to have a return type of the Primary Key so that a BMP bean can be inherited from a CMP bean.
The container generates the Primary Key based on the settings in the deployment descriptor for a CMP bean. The container hasn't generated the primary key yet when the ejbCreate method runs, because its waiting for you to load the virtual fields from the ejbCreate parameters. So in fact there is nothing you can return - you return "null" instead.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic