O'Reilly logo

Enterprise JavaBeans, Fourth Edition by Richard Monson-Haefel, Bill Burke, Sacha Labourey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

EntityContext

The first method called by the container after a bean instance is created is setEntityContext( ). This method passes the bean instance a reference to its javax.ejb.EntityContext, which is really the instance’s interface to the container.

The setEntityContext( ) method should be implemented by the entity bean developer so that it places the EntityContext reference in an instance field of the bean where it will be kept for the life of the instance. The definition of EntityContext is as follows:

public interface javax.ejb.EntityContext extends javax.ejb.EJBContext {
    public EJBLocalObject getEJBLocalObject( ) throws IllegalStateException
    public abstract EJBObject getEJBObject( ) throws IllegalStateException;
    public abstract Object getPrimaryKey( ) throws IllegalStateException;
}

As the bean instance is swapped from one EJB object to the next, the information obtainable from the EntityContext changes to reflect the EJB object to which the instance is assigned. This change is possible because the EntityContext is an interface, not a static class definition, so the container can implement the EntityContext with a concrete class that it controls. As the entity bean instance is swapped from one EJB object to another, the information made available through the EntityContext will also change.

The EntityContext.getEJBObject( ) method returns a remote reference to the bean instance’s EJB object. The EntityContext.getEJBLocalObject( ) method, on the other hand, returns a local reference ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required