method. When a client invokes the create() method on the remote home interface, it is delegated to a matching ejbCreate() method on the entity bean instance. The ejbCreate() method initializes the fields; in the case of the CabinBean, it sets the namevirtual field. The ejbCreate() method always returns the primary key type; with container- managed persistence, this method returns the null value. It s the container s responsibility to create the primary key. Why does it return null? Simply put, it makes it easier for a bean-managed enterprise bean to extend a container-managed enterprise bean. This is valuable for EJB vendors who support container-managed persistence beans by extending them with bean- managed persistence beans implementations it s a technique that was more common in EJB 1.1. Bean-managed persistence beans, which are covered in Chapter 10, always return the primary key type. Once the ejbCreate() method has executed, the ejbPostCreate() method is called to perform any follow-up operations. The ejbCreate() and ejbPostCreate() methods must have signatures that match the parameters and (optionally) the exceptions of the home interface s create() method. The ejbPostCreate() method is used to perform any post processing on the bean after its created, but before it can be used by the client. Both methods will execute, one right after the other, when the client invokes the create() method on the remote home interface. The findByPrimaryKey() method is not defined in container-managed bean classes. Instead, find methods are generated at deployment and implemented by the container. With bean-managed entity beans (entity beans that explicitly manage their own persistence), find methods must be defined in the bean class. In Chapter 10, when you develop bean-managed entity beans, you will define the find methods in the bean classes you develop. The CabinBeanclass implements javax.ejb.EntityBean, which defines five callback methods: setEntityContext(), unsetEntityContext(), ejbActivate(), ejbPassivate(), ejbLoad(), ejbStore(), and ejbRemove(). The container uses these callback methods to notify the CabinBean of certain events in its life cycle. Although the callback methods are implemented, the implementations are empty. The CabinBean is simple enough that it doesn t need to do any special processing during its life cycle. When we study entity beans in more detail in Chapters 6 through 11, we will take advantage of these callback methods. The Deployment Descriptor You are now ready to create a deployment descriptor for the Cabin EJB. The deployment descriptor performs a function similar to a properties file. It describes Copyright (c) 2001 O’Reilly & Associates 9
Our Colorado hosting facilities are located in Little Rock, Colorado. Colorado web hosting datacenter which we have is linked on five major US backbones which gives you assurance that your site will be online 24/7 a day. More details you can find out in Web Hosting Colorado part.