- EJB and JDBC
- Entity Bean Server Components
- Entity Bean Client Interfaces
- Entity Bean Configuration and Deployment
- Conclusions
Entity Bean Configuration and Deployment
As you saw in a the third article in this series, the root <ejb-jar> element contained an <enterprise-beans> element, which contained a collection of <session> elements. Instead of containing just <session> elements, the <enterprise-beans> element can also contain a collection of <entity> elements. Each <entity> element is used to describe the configuration and deployment of an individual entity bean.
The <entity> bean element, shown in Listing 1, defines entity bean metadata; a unique name in the EJB JAR file; the bean's class, interface, and primary key names; the type of entity bean; configuration parameters; references to other EJBs and database connections; security semantics; and elements to assist in the object-relational mapping for CMP entity beans. As an example, the entity-related elements of a CMP entity TShirt bean's ejb-jar.xml file are shown in Listing 1. You'll note that for the TShirt EJB, its <persistence-type> is marked as Container and a set of <cmp-field> elements defines the container-managed fields of this EJB. The primary key class field is indicated in the <primkey-field> as the SHIRT_ID field, which is of type java.lang.Integer, as defined in the <prim-key-class> field.
Listing 1 Example of EJB Entity Bean Deployment Descriptor Information
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.// [ic:ccc]DTD Enterprise JavaBeans 1.1//EN' [ic:ccc] 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'> <ejb-jar> <description>no description</description> <display-name>TSHIRT</display-name> <enterprise-beans> <entity> <description/> <display-name>TShirtEJB</display-name> <ejb-name>TShirtEJB</ejb-name> <home>ejava.ejbch36.tshirt.TShirtHome</home> <remote>ejava.ejbch36.tshirt.TShirt</remote> <ejb-class>ejava.ejbch36.tshirt.TShirtEJBean</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>java.lang.Integer</prim-key-class> <reentrant>False</reentrant> <cmp-field><field-name>SHIRT_ID</field-name></cmp-field> <cmp-field><field-name>SHIRT_SIZE</field-name></cmp-field> <cmp-field><field-name>COLOR</field-name></cmp-field> <cmp-field><field-name>DESIGN_FRONT</field-name></cmp-field> <cmp-field><field-name>DESIGN_BACK</field-name></cmp-field> <cmp-field><field-name>PICTURE_FRONT</field-name></cmp-field> <cmp-field><field-name>PICTURE_BACK</field-name></cmp-field> <cmp-field><field-name>ITEM_ID_FK</field-name></cmp-field> <primkey-field>SHIRT_ID</primkey-field> </entity> </enterprise-beans> ... </ejb-jar>
Vendor-specific deployment descriptor files to configure and deploy entity beans are also needed. Developers most often use GUI-based deployment tools provided by vendors to develop such files. What is perhaps most important about these vendor-specific XML files (aside from the JNDI-to-EJB name mappings for all EJBs) is the object-to-relational mappings that they contain for CMP entity EJBs.