• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFEJB, Page no 368, Question 5

 
Micheal Jacob
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can we not declare,

public int ejbCreate() throws javax.ejb.CreateException { }

in entity bean ?? Is this not a valid declaration ?

HFEJB says, it is wrong.
Pls advice.

Micheal.
 
Saagar Kappa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ejbCreate method is called by the Container to create the bean and it should not return any thing and should be void. Think about it. Who would the method return an integer to ??

Saagar
 
Micheal Jacob
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sagar,

Return type should be void for session bean, but for entity bean, it should be PK.

And my question was related to entity bean.

Micheal.
 
Arun
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont have the book with me now, but may be the reason it is invalid is because the return type should be the primary key class and not a primitive type??? So if the return type was Integer instead of int it would be valid then.
 
Saagar Kappa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Michael my mistake, I had exactly the same question when I did the chapter. I replied ur question in haste, without checking taht it was an entity bean... Since it is mentioned that the primary key can be an integer or a string, i felt that teh choice was valid too, but that leaves the question whether they were talking about a wrapped Integer or a primitive int..

Neways, hope someone else can clear this up..

Saagar
 
Micheal Jacob
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya, as you all say, i too think "int" is the trick here...

Anyway, thanks arun, sagar.

Micheal
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm only starting to study for SCBCD, so I'm not sure this will help.
But it is said that the prim-key-class element contains the fully-qualified name of an entity bean's primary key class. This should confirm what you are saying. Primitive types are not allowed. Wrapper classes should be used instead.
 
B.Sathish
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple way to reason out this : You need to return null from the ejbCreate () method of a CMP entity bean. You can't return null if the return type is a primitive. Hence the return type cannot be a primitive
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic