Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJBs extending EJBs  RSS feed

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

I want to club all my common methods (used across different EJBs) in one base EJB, so that I can extend this base EJB to the others and have those methods available for use.

Can somebody throw some light on how this can be achieved?

Thanks in advance.
Pratul
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36406
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pratul,
You can do this the same way you subclass any other class. Have your intermediate class extend EJBObject and have your concrete EJBs extend the intermediate class.

One thing though: From a design perspective, are these common methods really a logical superclass? If not, they could go into a utility class as static methods. This is cleaner and easier to reuse.
 
Pratul Chakre
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

Thank you for your response!

Well, I actually did implement the methods as static in Utility class and used them. But I want to explore the concept of inheritance in EJBs. Do you know of any post/document that explains this in detail?

Also, the intermediate class that you mentioned, is that NOT an EJB but only a standalone class extending javax.ejb.EJBObject?

Just to give you a brief insight of what I am trying to do:

I wrote some generic methods for doing a lookup of the home objects in order to create my bean objects. I wrote the methods as static in a utility class and used them. Now, I want to see if I can move them to another bean (say BaseBean) and then use them. Would you be able to explain further on how can I achieve this?

Thanks,
Pratul
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote some generic methods for doing a lookup of the home objects in order to create my bean objects. I wrote the methods as static in a utility class and used them. Now, I want to see if I can move them to another bean (say BaseBean) and then use them. Would you be able to explain further on how can I achieve this?


Why do you want to move them to a base EJB class. Why not keep it in a separate utility class.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36406
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given your example, what you are describing really should be a utility class. That said, it is still interesting to explore what it means to do it the other way.

You would want the BaseBean to be abstract. That way, it is just code and can't be instantiated. So it is not an EJB.

I don't know of any documents that describe inheritance in EJBs specifically because it is so rarely done. It works just like inheritance in any other class though. So you could look at any tutorial on inheritance.
 
Pratul Chakre
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thank you for your responses. Well, I have used the lookup methods in a static utility class, but like I mentioned earlier, I am just trying to explore the inheritance concept w.r.t EJBs.

here's what I tried:

I moved my JNDI lookup methods to the BaseBean. However, I did not expose these methods in my remote interfaces. Hence, even though it would have been possible to instantiate the bean (making it abstract would essentially mean it no longer is EJB), no methods would have been able to be accessed. Then, I created another bean (SampleBean), which extended this BaseBean, so all the methods in BaseBean were available to SampleBean.

However, this scenario did not work for me as I needed to use those lookup methods for locating a bean. So, what I managed to achieve was a Catch-22 situation whereby the methods to lookup the beans were in a bean itself; and to use those methods I had to lookup THAT bean and create an object.

That's when Jeanne's response previous response about how the functionality that is truly intended to be in a superclass made more sense.

So now, I am trying to create a scenario which I can use to explore inheritance in EJBs.

Meanwhile, if you have any sample that you have implemented and can share with me, would be immensely helpful to jump start.

Thanks,
Pratul
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!