Java Reference
In-Depth Information
L ISTING 12.8
Continued
this.ctx = ctx;
}
public void unsetEntityContext()
throws javax.ejb.EJBException,
java.rmi.RemoteException {
ctx = null;
}
12
}
The class includes all of the information you want to store as a quote entry in the database.
Each of the attributes in this class is a container-managed field. When you deploy the bean,
you will have to map each of these attributes to a field in the database. Also, it is important to
know that every container-managed field must be specified as a public attribute. This is so that
the container can handle them directly. This breaks some important encapsulation rules that are
generally followed in object-oriented (OO) design, however, because clients always access this
class through a remote interface, and it is not accessible to any code directly, it is all right to
declare the attributes as public.
A unique note on the ejbCreate() methods in a container-managed entity bean: Notice that it
returns null. This return value is actually ignored by the container, but it must return a value so
that the method signature matches that of a bean-managed bean. This way it is easier to switch
between the two methods of persistence, so that all of the bean classes appear to be the same.
You also see several callback methods that were not present in the session bean class,
ejbLoad() and ejbStore() . You might be able to guess what these methods do by their
names. Each of these methods is more important when dealing with a bean-managed bean,
however we will discuss them further in the section dealing with the lifecycle of entity beans,
“Entity Bean Life Cycle.”
The Quote Bean class is a very simple container-managed bean. We have looked at some of the
basic concepts involved in writing an entity bean; however, to develop an enterprise-level sys-
tem using EJB there is much more information required.
Deployment Descriptor
Writing the deployment descriptor for an entity bean is similar to doing so for a session bean.
The concept is the same, however the information required for an entity bean is different. The
information will go inside of the same ejb-jar.xml file. As a matter of fact all of the deploy-
ment information for every EJB that is packaged into one jar file is included in the same
ejb-jar.xml file. This includes both session and entity beans.
 
Search WWH ::




Custom Search