In EJB 2.0 Entity Beans, What is the difference between the local home interface and the remote home interface?

Christopher Pickslay

EJB 2.0 adds the notion of local beans, which are accessible only from within the JVM your beans are running in.

The idea behind this is that many beans you might create are never meant to be accessed by remote clients. For example, you may program beans meant for your public interface like Order and Invoice, and you may have other helper beans which are never meant to be instantiated by remote clients, like Inventory and SalesTaxCalculator. Or you might have an entire system that takes advantage of EJB's transaction management, persistence, etc, but which has no remote (i.e., outside the current JVM) clients at all.

With EJB 1.1, you had to implement remote client views for all these beans, even if you had no remote clients. This means that your home and remote interfaces had to extend javax.rmi.Remote, which puts several restrictions on them, including:

  • Any objects passed as parameters must be serializable
  • Parameters are passed by value, not by reference
  • Network and serialization overhead related to RMI
  • Client must handle RemoteException on all method calls
Local beans also have limitations, the primary one being that you can only access them from within the same JVM, so they don't make much sense for distributed applications. Also, if you're converting your old remote interfaces to local ones, you have to be careful about the pass-by-reference semantics, which may lead to unintended consequences.

Note that you can implement both remote and local interfaces to your beans. But in most cases it makes more sense to define your application model first, based on access, distribution, and deployment needs, and then decide on local vs. remote based on the tradeoffs.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact