Listing 1.

Locating and invoking a remote session EJB methodContext initCtx = new InitialContext();
Object obj = initCtx.lookup("java:comp/env/ejb/OrderEntry");
OrderEntryHome home = (OrderEntryHome)PortableObjectRemote(
obj, OrderEntryHome.class);
OrderEntry ref = home.create();

// Method must be invoked on a session reference
CustomerData data = ref.getOpenOrderForCustomer(cID);?

Listing 2.

Locating and invoking the equivalent remote entity EJB Home methodContext initCtx = new
 InitialContext();
Object obj = initCtx.lookup("java:comp/env/Customer");
CustomerHome ref = (CustomerHome)PortableObjectRemote(
obj, CustomerHome.class);

// Note how the method is invoked directly
CustomerData data = ref.getOpenOrder(cID);

Listing 3.

A typical message-driven bean implementationpublic class OrderSubmitMsgHandler implements
 MessageDrivenBean {
    private transient MessageDrivenContext context = null;
    // Interface supported by either the session Bean or entity Home
    private transient OrderEntry ref;

    public void ejbCreate() {
        // Cache the home according to either snippet one or two
    }
    public void ejbRemove() {}
    public void setMessageDrivenContext(MessageDrivenContext mdc) {   
        context = mdc;
    }
    // Message acknowledge and database update participate
    public void onMessage(Message inMessage) {
        // Parse the customer from the message
	try {
	    ref.submit(customer);
	}
        catch (CustomerDoesNotExist e) {
            // Send JMS message to reply queue from exception
        }
        catch (OrderNotOpen e) {
            // Send JMS message to reply queue from exception
        }
        catch (OrderHasNoItemsException e) {
            // Send JMS message to reply queue from exception
        }
    }
}