Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFE p368 #5 question

 
Van Nguyen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
5. Which are legal declarations for a CMP bean's ejbCreate methods?
d. public int ejbCreate() throws javax.ejb.CreateException
The book has it marked as not a valid declaration. I think it is, isn't it just overloading the create by returning an int? Can't I have something like:
public int ejbCreate() {
this.pk = pkGenerator();
return this.pk;
}
 
cyril vidal
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Van,
As far as I have understood, the primary key need to be a class. So you can't use int for this.
See 10.6.13 for more details.
Don't forget also that you have to fill a <prim-key-class> element in the Deployment descriptor.
Regards,
Cyril.
 
Van Nguyen
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply cyril,
so you're saying
- public Integer ejbCreate() throws CreateException ... is legal
- public int ejbCreate() throws CreateExecption ... is not legal
I'll take a look at the spec. Thanks for your help.
-Van
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by cyril vidal:
Hi Van,
As far as I have understood, the primary key need to be a class. So you can't use int for this.
See 10.6.13 for more details.
Don't forget also that you have to fill a <prim-key-class> element in the Deployment descriptor.
Regards,
Cyril.

I agree with Cyril.Only Objects can be the primary key. Usually we use the wrapper classes. Note also, that the EJB API methods accept/return java.lang.Object type for the primary key
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic