- 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.
@Stateless public class A implements Foo { ... } @Stateless 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:
@Stateless public class A implements Foo { ... } @Stateless public class B extends A implements Foo, Bar { ... }