Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

HFE p368 #5 question

 
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;
}
 
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
 
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
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic