Discussions

EJB design: Coding an EJB for Local & Remote access

  1. Coding an EJB for Local & Remote access (7 messages)

    I was wondering if anyone has encountered problems by making the remote object extend both the EJBLocalObject and EJBObject interface. Technically it seems like one could create the following:

    public interface Customer extends EJBObject, EJBLocalObject { ... }

    This would then allow:

    public interface CustomerHome extends EJBHome, EJBLocalHome {
        public Customer create()...
        public Customer findByPrimaryKey()...
    }

    Basically, I'm trying to make the code flexible without creating "extra" classes. Any thoughts or experience on this approach?
  2. mutltiple inheritance!!!!
  3. Local beans methods can be invoked only by the clients located in the same JVM as that of the bean. Your home interface extends both EJBHome and EJBLocalHome interface. In the create and finder methods you are returning Customer bean's component interface. Again in the component(remote) interface you r extending EJBObject and EJBLocalObject so how the container will understand what exactly is to be returned?

    When a remote client connects to your bean since remote interface is extending both EJBObject and EJBLocalObject will always get exceptions.
  4. For more information regarding the above please refer EJBSpecification 2.0 document chapter 5 local and remote client views. The specification says that although it is possible to provide both local and remote client views for an entity bean, typically the or the other should be provided.

    The specification further says that entity beans that have container managed relationships with other entity beans must be accessed in the same local scope as the related entity beans.

    If u want to provide both the viwes i.e. local and remote then better write separate interfaces.
  5. Are there any good examples or using Local Interfaces for Relationships in EJB2.0.

    Also if you have a one to one relationship how should you implement the constructer so you can pass the related object in on creation.

    Any ideas, Owen
  6. Vishal,

    I just went and read the spec and it does say it is not usual to provide a bean as both remote but local; however, it didn't say defining it as both is not recommended. If a local client access the bean, then the local remote/home will be used, and if a remote client access the bean, then the remote remote/home interfaces will be used. The container should be able to differenciate between which one to use...based on the request and the deployment descriptor mapping.

    Natalie
  7. Coding an EJB for Local & Remote access[ Go to top ]

    how if you specifying an ejb for each in the ejb-jar (1 for remote, 1 for local) but both bean use the same class?

    i suggest create a business interface to specify all the methods needed, and create a local and remote where each will extends the business interface...
  8. No way, the solution is to separate them. The Remote bean is compiled with stubs/skels for remote interchange and marshall, the local does not.