GeeCON Prague 2014*
The moose likes EJB and other Java EE Technologies and the fly likes ejbCreate() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "ejbCreate()" Watch "ejbCreate()" New topic
Author

ejbCreate()

dhan hazarika
Greenhorn

Joined: Feb 10, 2004
Posts: 3
why ejbCreate()(CMP) returns null when it is supposed to return the Primary key?
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

dhan,

This question (and in retrospect, your other one) belong and will be better answered in the EJB forum.

I'm going to move them both there.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
For CMP beans the EJB Container is actually responsible for implementing the persistance logic. Therefore, it is the Containers responsibility to create and return an instance of the Primary Key class for your bean. The developer merely returns null because the Container is going to ignore it anyways.
Dave Cronin
Ranch Hand

Joined: Apr 25, 2003
Posts: 114
Another point is that the client code calling the EJB does not directly call the bean code that you develop. It actually calls, from the create() method, a class that the EJB container implements, subclassed from the your EJB. In this class the ejbCreate really does return a primary key. So you return null from ejbCreate because you don't need to worry about what kind of primary key gets returned.


Dave Cronin
SCJP, SCWCD, SCBCD
Sergiu Truta
Ranch Hand

Joined: Dec 16, 2003
Posts: 121
When using CMP you always return Null, and when using BMP you return the Primary Key.


...watch me...as I'm walking the path...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ejbCreate()