• 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

Should null be the return value for ejbCreate

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am going through Head First EJB book. I see that the ejbCreate method for CMP returns null. Doesnt it need to return the primary key. Another doubt is, as the container creates the record in the DB, does the container manages to give the reference of primary key object to EntityContext and our EJB object, (though we return null, if that should be so).
Can any one please clear these 2 points.
Arun.
 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Yes, the ejbCreate should return null. But it's return type MUST be the primary key type.

The goal of the ejbCreate method is to give a value to the cmp field, at least for those used by the pk. When this is done, the container reads the pk fields values, creates the DB row using pk and cmp fields, creates an EJBObject and an EntityContext and gives them a reference to the PK.

After this, the bean receives references to its EJBObject and context and the ejbPostCreate method is called.

So no need to actually return the pkey:
- the ejbCreate return type allows to know which fields to take for the pk;
- the values set in cmp fields during ejbCreate method are used to get the pk and create the DB row.

Hope this is clear.
 
Arun Kandregula
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Frederic Esnault:
Hi,

Yes, the ejbCreate should return null. But it's return type MUST be the primary key type.

The goal of the ejbCreate method is to give a value to the cmp field, at least for those used by the pk. When this is done, the container reads the pk fields values, creates the DB row using pk and cmp fields, creates an EJBObject and an EntityContext and gives them a reference to the PK.

After this, the bean receives references to its EJBObject and context and the ejbPostCreate method is called.

So no need to actually return the pkey:
- the ejbCreate return type allows to know which fields to take for the pk;
- the values set in cmp fields during ejbCreate method are used to get the pk and create the DB row.

Hope this is clear.

 
Arun Kandregula
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Frederic.
 
reply
    Bookmark Topic Watch Topic
  • New Topic