Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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

legal ejbCreate method

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thank you very much
Cal
 
Nils Mueller
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
brevity is the soul of wit - shakepeare. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic