• 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

ejbCreate() method return

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic