Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance & entity beans

 
vikram goyal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still not clear about inheritance in entity beans,if its possible
then what are the issues to consider .
Types of inheritance we implement.
can any one give me a simple example.

thanx
V
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,
Your entity bean is free to implement another Java class. EJB supports inheritance just as Java does, but EJB does *not* (at this time) support what they call "bean inheritance". Bean inheritance would give you the capability to inherit not just the things you'd inherit through the Java language, but also some of the 'beanness'. If you're familiar with non-enterprise Javabeans, they DO support bean inheritance (through things like BeanInfo). But EJB does not.
So, you can go ahead and have your bean inherit from another class. In EJB 1.1, it was not uncommon to subclass a bean-managed entity bean and make it container-managed, which is why the ejbCreate() method of a CMP bean has the same return type (the pk) even though the Container does not want or need you to return the PK from a CMP bean, and you are only supposed to return 'null' from a CMP bean.
If some form of bean inheritance were possible, it might mean, for example, that the deployment descriptor of the superclass bean would be picked up when you deploy the subclass bean, and then you might create only a *partial* DD for the subclass bean, perhaps putting in ONLY the parts of the DD that you want to be different from the superclass bean's behavior. There would be an awful lot of issues and complexities to work out, but bean inheritance might be really cool... but it's not supported now (and I don't believe in 2.1, either).
cheers,
Kathy
 
Amer Khan
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple example;
Inheritance within bean class implementations and component interfaces allow you to build a certain amount of layering into a design,just as we would if we were't using EJBs.Typically , stop subclassing when you reach the first concrete entity bean along a branch in the inheritance tree.The first step in this approach is create an abstract implementation of EntityBean for example

public abstract class AbstractEntity implements EntityBean{

protected EntityContext ctx;
public void ejbActivate(){}
public void ejbLoad(){}
public void ejbPassivate(){}
public void ejbRemove() throws RE{}
public void ejbStore(){ }
public void setEntityContext(EntityContext newCtx){
ctx=newCtx;
}
public void unsetEntityContext(){
ctx=null;
}
}
This class does little more than manage the assignment of the EntityContext,but even that reduces what you have to implement in a concrete
entity class.if our design called for any other behaviour common to all entity beans,this class would provide a place to implement that.

(concrete entity bean)
public class MyEntityBean extends AbstractEntity implements EntityBean{
/*
No implementation for EntityBean interface methods required here(you can always override them.)
*/
}
It isn't neccessary for this class to implement EntityBean, but some development tools don't reconize a class as an enterprise bean if it doesn't explicitly say "implements" the corresponding interface.
[ November 26, 2003: Message edited by: Amer Khan ]
 
vikram goyal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
V
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Weblogic 8.1 workshops also uses inheritance. If you try to create a stateless session thru the wizard, it inherits from a standard class "GenericSessionBean" or something like that. This beans has the lifecycle/callback methods and also some System.out.println methods.
The session bean class that you implement has only your business methods.
I guess this feature of weblogic workshop is for more code clarity.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic