• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic