• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris

ejbCreate() method return

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.

Posts: 2968
  • 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.
Everybody's invited. Except this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
    Bookmark Topic Watch Topic
  • New Topic