• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMP-ejbCreate()

 
sanneel paul
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In CMP

Why ejbCreate() returns null value ???

PG:331 HFEJB
public String ejbCreate(String last,String first){
// Assign argument to persistant field

this.setLastName(last);
this.setFirstName(first);

this.setPrimaryKey(this.makeKey());
return null; ///??? Why "null"

}
 
jeff mutonho
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm also confused by this , because on page 268 ejbCreate is implemented as follow

public String ejbCreate(String last,String first){
lastName=last;
firstName=first;
primaryKey=this.getPK();
//DB INSERT
return primaryKey;
}

Why then on page 331 ,are we returning null?
 
Ramakrishnan Viswanathan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Section 10.5.2 Bean Provider�s entity bean instance�s view on Page 171 of EJB 2.0 Spec states:

The implementation of the Bean Provider�s ejbCreate<
METHOD>(...) methods should be coded to return a null


Also please read the footnote [14] on this page.
 
Ramakrishnan Viswanathan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of entity bean are we talking about here? The responsibility of creating the actual entity in the data store is not the same for BMP and CMP.


In CMP, after ejbCreate(), the container creates the entity representation in the database. You just set the PK values and return null from ejbCreate(). --> The SCBCD exam focuses on CMP

In BMP, it is the responsibility of the bean provider for creating the entity representation in the database. You return the primary key from ejbCreate() to the container so that the container can identify which data your instance represents.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See also:
ejbCreate() method return
 
Accenture RS
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sanneel paul:
In CMP

Why ejbCreate() returns null value ???

PG:331 HFEJB
public String ejbCreate(String last,String first){
// Assign argument to persistant field

this.setLastName(last);
this.setFirstName(first);

this.setPrimaryKey(this.makeKey());
return null; ///??? Why "null"

}


===================
In CMP (EJB 1.1 Spec) ejbCreate returns null so that container managed beans can be extended to create Bean Managed Beans.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic