• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Why return null from entity bean ejbCreate()

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page 331 of HF there is a note on the bottom of the page that says "return null?? What's up with that?" I couldn't find the answer in the book so "what IS up with that?" Why do we return null from ejbCreate()?
Thanks in advance.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because, after the bean has been created, it is the responsibility of the container to return the primary key instance associated with the entity.
Also sometimes the priimary key is not know (unknown primary key) - so you would not always be able to return the primary key class. That;s the reason I guess, the spec says that null has to be returned, so that the Container can make the decision as to what (primary key class) is to be returned from ejbCreate
Hope that helps
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer is :
This is for CMP beans. as the container is managing the persistence no need to return anything. But, for BMP Beans container has to make sure that the ejbCreate() is completed successfully by getting the PrimaryKey class. ( BMP beans are out of scope for the exam.)
To make it same signature of ejbCreate() for both BMP and CMP beans, it is specified to return null for CMP entity beans.
-Prasad
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy,
Yes, Prasad has the right answer... the *original* idea was that you could take a BMP bean, and subclass it to be a CMP bean, so the ejbCreate() method had to be the same... I think they still explain it that way in the 2.0 spec. Keith, I think that's kind of funny (in a sad way) that I actually did say "What's up with that?" and then never explained it. It was supposed to be in a Q & A Sorry!
cheers,
Kathy
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok...In CMP2.0 Entity bean, the spec says, we return null, so we return null.
But what happens if I return the primary key object itself. In most cases, I think I have access to the primary key object in ejbCreate() method.
example :
public String ejbCreate(String key) {
setID(key);
//return null;
return key;
}
Any comments?
One of the CMP examples in Ed Roman's book has similar code.
I wonder if it is right. (7.6, p:190 and p:191 of the pdf file, Chapter 7(CMP))
 
This one time, at bandcamp, I had relations with a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic