• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Should null be the return value for ejbCreate

 
Arun Kandregula
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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.
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks Frederic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic