File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "ejbCreate()" Watch "ejbCreate()" New topic


dhan hazarika

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


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
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. I'm walking the path...
I agree. Here's the link:
subject: ejbCreate()
jQuery in Action, 3rd edition