Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days

Now look at the steps involved in developing an entity bean, as shown in Figure 12.2.

Figure 12.2. Flowchart for developing an entity bean using CMP.

The first step in developing an entity bean is to define the requirements of the application. This involves understanding the different entities involved, their interaction, and the work flow of the application.

In the second step, you identify the primary business objects in the application. These business objects are candidates for modeling as entity beans. Ideally, the database design will enable you to define the business objects involved in the application. These database entities are the basis for designing entity beans in the object model. You'll need to define the class diagram and sequence diagram of the entities involved in the application. The class diagram will consist of the classes and interfaces that constitute the entity bean. The sequence diagram will help you to define the dynamic interaction between different classes of the application. For an entity bean you also need to define the following:

  • Entity bean's remote interface extends javax.ejb.EJBObject (or javax.ejb.EJBLocalObject).

  • Entity bean's home interface extends javax.ejb.EJBHome.

  • Entity bean's implementation class implements javax.ejb.EntityBean.

  • Entity bean's primary class implements Serializable.

The entity bean's implementation class will be an abstract class with no implementation code for the business methods or the life-cycle methods. The container's tools will generate the implementation code for the business methods and the life-cycle methods.

Step 3 is where you compile all of the source code Java files and generate your .class files. After this, you'll register the entity bean in the deployment descriptor files and define the field mapping for the CMP in the ejb-jar.xml, weblogic-cmp-rdbms-jar.xml and weblogic-ejb-jar.xml files. These deployment descriptor files must be copied in subdirectory META-INF under the directory where your source files are located. Once your .class files and deployment descriptor files are ready, package them all together in a Java archive file. This Java archive package should now be compiled using the weblogic.ejbc compiler to generate the final Java archive. The final Java archive contains the EJB container-generated classes for EJBHome, EJBObject, the stub and skeleton classes, and the JDBC code that creates a JDBC connection, creates statements, executes SQL statements, and retrieves results (if required).

Finally, you need to deploy the Java archive that you generated in the previous step in the WebLogic Server environment. You can deploy the entity EJB in three different ways:

  • Administration Console Configure a new EJB.

  • Administration Console Install a new EJB.

  • Manually deploy the EJB on command prompt using the deploy tool provided by the WebLogic Server.

The entity EJB is now ready for use by any EJB client.

Категории