Rules for Developing EJB 3.x Session Beans

5 March 2012 By Nithya Vasudevan 4,308 views One Comment
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×
  • There must be atleast one business interface for a session bean.
    • The interface can be marked as @Remote, @Local or @WebService.
    • EJB 3.1 provides a no-interface view for the client in which the bean is not required to implement the business interface.
    • The interface is allowed to have superinterfaces.
  • Session bean class must be a concrete class which should implement the business interface. This class cannot be defined as final, abstract since container might need to manipulate this class.
    • Bean must be marked either as @Stateless or @Stateful or @Singleton (EJB 3.1)
  • Bean class must have no-argument constructor. Container uses this constructor to create bean instances. NOTE: If there is no constructor defined then the compiler inserts a default constructor.

Session Bean Superclasses

  • A session bean class is permitted to have superclasses that are themselves session bean classes.
  • The use of session bean classes as superclasses merely represents a convenient use of implementation inheritance, but does not have component inheritance semantics.
public class A implements Foo { ... }

public class B extends A implements Bar { ... }

Assuming Foo and Bar are local business interfaces, session bean A exposes local business interface Foo and session bean B exposes local business interface Bar, but not Foo.

Session bean B would need to explicitly include Foo in its set of exposed views for that interface to apply. For example:

public class A implements Foo { ... }

public class B extends A implements Foo, Bar { ... }

Tags: ,

  • Shashi Bhushan

    Getting Warning in Netbeans : A session bean must not extend another session bean