• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inheritance in EJBs

 
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can i use inheritance in EJBs.If yes,How can i ensure that the super class object is created before i call a Child EJB's method?
Any pointers for the same will also be helpful.
Thanks in advance
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've used inheritance with stateless session beans and you'll be fine if you keep the following in mind:
Bean Class:
The child bean class must extend the parent bean class. Make sure you call super.setSessionContext(ctx) in the childs setSessionContext() method if you are performing any initialization in the parent method.
Remote Interface:
Make sure the child remote interface extends the parent remote interface. The child interaface automatically inherits the parents remote methods, so there is no need to define them in the child remote interface, unless you plan to override, just like regular inheritance, there really is no difference.
Home interface:
The child home interface does NOT extend the parent home interface; it simple extends EJBHome.
Deployment descriptor:
If you will be accessing the child bean from your client code, then you only need specify the child EJB classes and JNDI name in the descriptor. There is no need to specify anything regarding the parent bean.
Hope it helps,
Raffi
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure you can. Common use is for example to create AbstractSession with EJB specific code:
public javax.ejb.SessionContext getSessionContext() {
return mySessionCtx;
}
/**
* setSessionContext
*/
public void setSessionContext(javax.ejb.SessionContext ctx) {
mySessionCtx = ctx;
}
/**
* ejbCreate
*/
public void ejbCreate() throws javax.ejb.CreateException {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() {
}

and then you implement your own class which extends AbstractSession class.
Answer to second part is that everything is one object. So don't worry about that. But be carefull if you use it in Entity beans.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic