Heterogeneous Interfaces

This chapter deals with different views which which EJBs can expose to their prospective clients. These are as follows

  • Local

  • Remote

  • No-interface

  • Web service

What are its benefits ?

  • Flexibility: Gives you the ability to choose the appropriate view for your business requirements. You can also mix and match views (subject to rules) if need be

  • Ease of use: View management is declarative in nature (annotation driven) and hence it is naturally easy to adopt

  • Interoperability: Helps business logic written using EJB 2.x specification adapt to the its modern (3.x) counterpart. Again, this adaptability is managed via annotations

Web Service

This is typically in the form of a SOAP or REST web service. For further details, please refer to the Web Services support chapter

@Local

This annotation can be used on a session bean interface or the bean implementation class itself - either ways, it makes the session bean available to clients in the same JVM.

The container exchanges instances of these beans by reference (within the same JVM). Hence Local session bean interfaces tend to be more efficient when compared to their remote (@Remote) counterparts (discussed soon)

There are multiple ways in which it can be used

Default

EJB implements an interface (without using @Local). The container applies local bean semantics by default

The implementation

EJB implements an interface which is annotated with @Local

EJB implements an interface which is not annotated with @Local

EJB does not implement the interface but designates it as its local view

@Remote

This annotation is also applicable for a session bean interface or the bean implementation class itself. It makes the session bean available to clients outside the JVM in which it is deployed

The container exchanges instances of these beans by value i.e. communication using remote EJB views requires serialization (of method parameters and return types)

Possible usage combinations (similar to @Local)

  • EJB implements an interface which is annotated with @Remote

  • EJB implements an interface which is not annotated with @Remote

  • EJB does not implement the interface but designates it as its remote view

@LocalBean

The usage of the @LocalBean annotation is synonymous with the no-interface view which means that the EJB does not implement any interfaces.

Why is this even required ? Why not leave the bean alone (with just the @Stateless annotation) ?

Strictly speaking, @LocalBean is supposed to be used in scenarios where

  • the no-interface view needs to co-exist with other views which a session bean might expose

  • in case it implements another interface(s) which are not remote/local views

@LocalHome

This annotation acts as a bridge b/w EJB 3.x and 2.x style session beans i.e. it can help 3.x session beans to be compatible with clients of EJB 2.1 (and before) session beans (since it was mandatory for beans to have home interfaces)

@RemoteHome

This is the remote equivalent of the @LocalHome annotation. It helps remote EJB 3.x beans adapt to EJB 2.1 style beans which previously required the existence of home interfaces

@Init

This annotation is applied on a method is only required for stateful session beans that provide an adapted remote/local home interface (using @RemoteHome or @LocalHome annotations discussed above)

Last updated

Was this helpful?