Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

legal ejbCreate method

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this a legal declarations for a CMP bean's ejbCreate method?
public int ejbCreate() throws javax.ejb.CreatException

Thanks
Cal
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

remember (or learn an ejbCreate() method always has a void return type.
I suppose you could compile it (if you returned an int) but you couldn't deploy it.
ejbCreate() --> always void
greetz
Nils
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Calvin, Nils: There are different rules regarding the signature of method ejbCreate depending on the type of EJB.
In case of a session bean, there is only one: public void ejbCreate() throws javax.ejb.CreateException;
In case of an entity bean: return type must be an Object - so primitives will not do. If you chose a primitive, then you would not be able to use the remove method on the Home interface which takes an Object as primary key argument.
Hope it clarifies.
 
Calvin Kong
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much
Cal
 
Nils Mueller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ups, you're right, for sure.
ejbCreate for SessionBeans => void
ejbCreate for EntityBeans has return type of the primary key!
For above mentioned reasons and also:
public Object getPrimaryKey() throws RemoteException
in the component interface.
thanks!
Nils
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ejbCreate for CMP entity bean must return null.
public PrimaryKeyClass ejbCreate(....) {
....
return null;
}
public void ejbPostCreate(...) {
}

ejbCreate for session bean :
//Stateless session bean : It must have ejbCreate() method with no-argument.
public void ejbCreate() {
}
//Stateful session bean
public void ejbCreate(.....) {
}
All right?
 
pie. 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
reply
    Bookmark Topic Watch Topic
  • New Topic