Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB Inheritance and lifecycle  RSS feed

 
Pratul Chakre
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I would like to know how the lifecycle of an inherited EJB works.

For example: I have an 'InheritedBean' which is derived from a 'BaseBean'. When the first call to instantiate the 'InheritedBean' is made, the 'BaseBean' is instantiated after which the 'InheritedBean' is instantiated.

Now, if another instance of the 'InheritedBean' is created, will the previous 'BaseBean' instance be re-used for the new inherited bean? Or is it that the 'BaseBean' instance is tied to the previous 'InheritedBean' instance and cannot be re-used until the lifecycle of the inherited bean is completed?

Any help on this would be much appreciated.

Thanks,
Pratul Chakre
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pratul,
InheritedBean extends another class which happens to be be a bean. This works just the way regular Java inheritance works. There is only one EJB instantiated (the subclass.)

For example: I have an 'InheritedBean' which is derived from a 'BaseBean'. When the first call to instantiate the 'InheritedBean' is made, the 'BaseBean' is instantiated after which the 'InheritedBean' is instantiated.

Sort of. While BaseBean's constructor is called, you don't really have two objects here. You have one (InheritedBean) that has the attributes/methods of it's parent.

Now, if another instance of the 'InheritedBean' is created, will the previous 'BaseBean' instance be re-used for the new inherited bean? Or is it that the 'BaseBean' instance is tied to the previous 'InheritedBean' instance and cannot be re-used until the lifecycle of the inherited bean is completed?

You get a new instance of InheritedBean.

Remember, there aren't a lot of instances of java.lang.Object floating around - which every class extends.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!