Skip to main content

JBoss to GlassFish: Session Bean and Component inheritance

Posted by sekhar on February 3, 2009 at 7:51 AM PST

Migration Issue: This migration issue is related to the
inheritance of client view in a session bean. Consider the
following code fragment where session beans A and B exposes
local business interface ( or client views using EJB 3.X
specification terminology).

    // Assume Foo is a local business interface         
    public class A implements Foo { ... }

    // Assume Bar is a local business interface
    public class B extends A implements Bar { ... }

So does session bean B expose Foo or not ? This was unclear on EJB 3.0,
JBoss allows it while GlassFish v2 does not. Hence the migration issue.

EJB 3.1 clarified the inheritance semantics. According to EJB 3.1,
session bean B will expose only Bar but not Foo i.e. there is no
inhertiance of client views. EJB 3.1, Section, "Session
Bean Superclass" states the following:

For the purposes of processing a particular session bean
class, all superclass processing is identical regardless of
whether the superclasses are themselves session bean classes. In
this regard, the use of session bean classes as superclasses
merely represents a convenient use of implementation
inheritance, but does not have component inheritance

Migration Path:So, the migration path for this issue is to
follow EJB 3.1 semantics. i.e. if you want session bean B to expose
Foo, then explicitly include Foo in the interfaces exposed by
session bean B as follows:

    public class A implements Foo { ... }
    // Add Foo to expose Foo in session bean B's client views.
    public class B extends A implements Foo, Bar { ... }
Related Topics >>


Hello Sir! Sorry to have popped my issue again. Actually i am not able to find a solution for weblogic 10.3 . I have 2 queries with this regard: 1> Is there a way i could implement EJB3.1 to make use of the session bean superclass spec or make certain changes in ejb3.0 itself in my weblogic version? I have made my superclass as a general bean to solve this problem. But it may give lookup problems later. 2> how to lookup local interface, i mean , is there anything like .lookup("MyLocal/local") for weblogic. I cannot make use of injections as there are many such local lookups. So any way in which i can have local lookup dynamically?, as an example: String component = "someEJB"; ctx.lookup(component); Remote lookup, no problem, but i am uncomfortable using full path for remote interface in the syntax i.e, lookup("MyEJB#fullpath_to_MYEJBRemote") as i have to do it dynamically , Kindly give me a solution for my problem, I may be missing something very basic ! Thank you, Regards, Vidhya.

Ok! I got the problem! Thank you for giving me this realization that weblogic 10.3 supports ejb 3.0! Thank you Sir! Regards, Vidhya

Sekhar's write-up is correct. The EJB 3.0 specification does not allow inheritance between two session bean classes. It's possible that some vendors support it but use of that feature on any Java EE 5 (EJB 3.0) products is not portable. The EJB 3.1 spec will relax the requirement to allow for a form of concrete session bean class inheritance, but it's up to the bean developer to explicitly specify which client views are exposed by the subclassing bean.

I have forwarded your comment to Ken Saks, EJB spec lead for a comments/solution to this. EJB 3.0 core spec seems to disallow a session bean extending another session bean. From Section 4.6.2, EJB 3.0, "EJB Core Contracts and Requirements" : "A session bean class must not have a superclass that is itself a session bean class." However, EJB 3.1 , Section, "Session Bean Superclass" does allow it: "A session bean class is permitted to have superclasses that are themselves session bean classes." And WebLogic 10.3 (per release note) implements EJB 3.0.

Hi sir! Good post ! But Im wondering is it possible to have a session bean superclass for another session bean? I surfed on the net, I found that its in ejb3 spec tat it cannot extend another session bean! I am dealing with this same problem and need to find a solution. If you can help me with this then I'll be grateful to you! I am using to deploy in weblogic 10.3 Thank you, Vidhya