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

legal ejbCreate method

 
Calvin Kong
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
 
Nils Mueller
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
 
Nicky Moelholm
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
 
somkiat puisungnoen
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic