aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes inheritance in EJBs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "inheritance in EJBs" Watch "inheritance in EJBs" New topic
Author

inheritance in EJBs

william kane
Ranch Hand

Joined: Nov 21, 2000
Posts: 260
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


Help me!Help you!!!
SAFROLE YUTANI
Ranch Hand

Joined: Jul 06, 2001
Posts: 257
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
Vladimir Ergovic
Ranch Hand

Joined: Apr 22, 2001
Posts: 63
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.


Vladimir Ergovic
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inheritance in EJBs