web server - Borland Technical Publications
web server - Borland Technical Publications web server - Borland Technical Publications
Chapter 15 15Entity Beans and Table Mapping for Chapter CMP 2.0 Important Here we'll examine how entity beans are deployed in the Borland Enterprise Server and how persistence of entities can be managed. This is not, however, an introduction to entity beans and should not be treated as such. Rather, this document will explore the implications of using entity beans within Borland Partitions. We'll discuss descriptor information, persistence options, and other container-optimizations. Information on the Borland-specific deployment descriptors and implementations of Container-Managed Persistence (CMP) will be documented in favor of general EJB information that is generally available from the J2EE Specifications from Sun Microsystems. For documentation updates, go to www.borland.com/techpubs/bes. Entity Beans Entity beans represent a view of data stored in a database. Entity beans can be finegrained entities mapping to a single table with a one-to-one correspondence between entity beans and table rows. Or, entity beans can span multiple tables and present data independent of the underlying database schema. Entity beans can have relationships with one another, can be queried for data by clients, and can be shared among different clients. Deploying your Entity Bean to one of the Borland Enterprise Server Partitions requires that it be packaged as a part of a JAR. The JAR must include two descriptor files: ejbjar.xml and the proprietary ejb-borland.xml file. The ejb-jar.xml descriptor is fullydocumented in the J2EE 1.3 Specification. The DTD for ejb-borland.xml is reproduced in this document and aspects of its usage documented here. The Borland proprietary descriptor allows for the configuration of a number of properties that can be set to optimize container performance and manage the persistence of your entity beans. Chapter 15: Entity Beans and Table Mapping for CMP 2.0 127
Container-managed persistence and Relationships Container-managed persistence and Relationships Borland's EJB container provides tools that generate the persistence calls at the time that the entity bean is deployed; that is, when the entity bean is installed into a Partition. The tools use the deployment descriptors to determine the instance fields which must be persisted. Instead of coding the database access directly in the bean, the bean provider of a container-managed entity bean must specify in the deployment descriptor those instance fields for which the container tools must generate access calls. The container has sophisticated deployment tools capable of mapping the fields of an entity bean to its data source. Container-managed persistence has many advantages over bean-managed persistence. It is simpler to code because the bean provider does not have to code the database access calls. Handling of persistence can also be changed without having to modify and recompile the entity bean code. The Deployer or Application Assembler can do this by modifying the deployment descriptor when deploying the entity bean. Shifting the database access and persistence handling to the container not only reduces the complexity of code in the bean, it also reduces the scope of possible errors. The bean provider can focus on debugging the business logic of the bean rather than the underlying system issues. Borland's Persistence Manager (PM) not only persists CMP fields but also CMP relationships. The container manages bean relationships and maintains the referential integrity of these relationships. Just as you defined container-managed persistence fields in a bean's deployment descriptor, you can now define container-managed relationship fields in the deployment descriptor. The container supports relationships of various cardinalities, including one-to-one, one-to-many, and many-to-many. Packaging Requirements Like session beans, entity beans can expose their methods with a remote interface or with a local interface. The remote interface exposes the bean's methods across the network to other, remote components. The local interface exposes the bean's methods only to local clients; that is, clients located on the same EJB container. Entity beans that use EJB 2.0 container-managed persistence should use the local model. That is, the entity bean's local interface extends the EJBLocalObject interface. The bean's local home interface extends the EJBLocalHome interface. You must deploy these interfaces as well as an implementation of your bean's class. Each Entity Bean must also have corresponding entries in its JAR's deployment descriptors. The standard deployment descriptor, ejb-jar.xml contains essentially three different types of deployment information. These are: 1 General Bean Information: This corresponds to the elements found in the descriptor file and is used for all three types of beans. This information also includes information on the bean's interfaces and class, security information, environmental information, and even query declarations. 2 Relationships: This corresponds to the elements found in the descriptor file and applies to entity beans using CMP only. This is where containermanaged relationships are spelled out. 3 Assembly Information: This corresponds to the element which explains how the beans interact with the application as a whole. Assembly information is broken down into four categories: ■ ■ Security Roles: simple definitions of security roles used by the application. Any security role references you defined for your beans must also be defined here. Method Permissions: each method of each bean can have certain rules about their execution. These are set here. 128 BES Developer’s Guide
- Page 87 and 88: Web Service providers Java:RPC prov
- Page 89 and 90: How Borland Web Services work
- Page 91 and 92: Packaging Web Service Application A
- Page 93 and 94: Tools Overview Java2WSDL tool Note
- Page 95 and 96: 84 BES Developer’s Guide
- Page 97 and 98: Client view of an enterprise bean L
- Page 99 and 100: Client view of an enterprise bean E
- Page 101 and 102: Managing transactions Managing tran
- Page 103 and 104: Support for JNDI Support for JNDI T
- Page 105 and 106: EJB to CORBA mapping A CORBA progra
- Page 107 and 108: 96 BES Developer’s Guide
- Page 109 and 110: Application Client architecture Pac
- Page 111 and 112: Document Type Definitions (DTDs) my
- Page 113 and 114: Support of references and links The
- Page 115 and 116: Use of Manifest files Use of Manife
- Page 117 and 118: 106 BES Developer’s Guide
- Page 119 and 120: Sessions in secondary storage If yo
- Page 121 and 122: 110 BES Developer’s Guide
- Page 123 and 124: Container-managed persistence and R
- Page 125 and 126: Implementing an entity bean Generat
- Page 127 and 128: Container-Managed Persistence in Bo
- Page 129 and 130: Container-Managed Persistence in Bo
- Page 131 and 132: Setting Properties Setting Properti
- Page 133 and 134: Setting Properties into a BLOB. The
- Page 135 and 136: Setting Properties Automatic table
- Page 137: 126 BES Developer’s Guide
- Page 141 and 142: Container-Managed Persistence in Bo
- Page 143 and 144: Container-Managed Persistence in Bo
- Page 145 and 146: Container-Managed Persistence in Bo
- Page 147 and 148: Container-Managed Persistence in Bo
- Page 149 and 150: Container-Managed Persistence in Bo
- Page 151 and 152: Container-Managed Persistence in Bo
- Page 153 and 154: 142 BES Developer’s Guide
- Page 155 and 156: Setting Properties J2EE 1.3 Entity
- Page 157 and 158: Setting Properties Figure 16.2 Edit
- Page 159 and 160: Setting Properties Table 16.1 ejb.m
- Page 161 and 162: Setting Properties Table 16.3 Table
- Page 163 and 164: Setting Properties Security Propert
- Page 165 and 166: Aggregate Functions in EJB-QL Selec
- Page 167 and 168: Support for ORDER BY Support for OR
- Page 169 and 170: Overriding SQL generated from EJB-Q
- Page 171 and 172: Container-managed data access suppo
- Page 173 and 174: 162 BES Developer’s Guide
- Page 175 and 176: Generating primary keys from a cust
- Page 177 and 178: Implementing primary key generation
- Page 179 and 180: Transaction manager services Consis
- Page 181 and 182: Transaction manager services When t
- Page 183 and 184: Transaction manager services Follow
- Page 185 and 186: Declarative transaction management
- Page 187 and 188: Declarative transaction management
Container-managed persistence and Relationships<br />
Container-managed persistence and Relationships<br />
<strong>Borland</strong>'s EJB container provides tools that generate the persistence calls at the time<br />
that the entity bean is deployed; that is, when the entity bean is installed into a<br />
Partition. The tools use the deployment descriptors to determine the instance fields<br />
which must be persisted. Instead of coding the database access directly in the bean,<br />
the bean provider of a container-managed entity bean must specify in the deployment<br />
descriptor those instance fields for which the container tools must generate access<br />
calls. The container has sophisticated deployment tools capable of mapping the fields<br />
of an entity bean to its data source.<br />
Container-managed persistence has many advantages over bean-managed<br />
persistence. It is simpler to code because the bean provider does not have to code the<br />
database access calls. Handling of persistence can also be changed without having to<br />
modify and recompile the entity bean code. The Deployer or Application Assembler can<br />
do this by modifying the deployment descriptor when deploying the entity bean. Shifting<br />
the database access and persistence handling to the container not only reduces the<br />
complexity of code in the bean, it also reduces the scope of possible errors. The bean<br />
provider can focus on debugging the business logic of the bean rather than the<br />
underlying system issues.<br />
<strong>Borland</strong>'s Persistence Manager (PM) not only persists CMP fields but also CMP<br />
relationships. The container manages bean relationships and maintains the referential<br />
integrity of these relationships. Just as you defined container-managed persistence<br />
fields in a bean's deployment descriptor, you can now define container-managed<br />
relationship fields in the deployment descriptor. The container supports relationships of<br />
various cardinalities, including one-to-one, one-to-many, and many-to-many.<br />
Packaging Requirements<br />
Like session beans, entity beans can expose their methods with a remote interface or<br />
with a local interface. The remote interface exposes the bean's methods across the<br />
network to other, remote components. The local interface exposes the bean's methods<br />
only to local clients; that is, clients located on the same EJB container.<br />
Entity beans that use EJB 2.0 container-managed persistence should use the local<br />
model. That is, the entity bean's local interface extends the EJBLocalObject interface.<br />
The bean's local home interface extends the EJBLocalHome interface. You must deploy<br />
these interfaces as well as an implementation of your bean's class.<br />
Each Entity Bean must also have corresponding entries in its JAR's deployment<br />
descriptors. The standard deployment descriptor, ejb-jar.xml contains essentially<br />
three different types of deployment information. These are:<br />
1 General Bean Information: This corresponds to the elements<br />
found in the descriptor file and is used for all three types of beans. This information<br />
also includes information on the bean's interfaces and class, security information,<br />
environmental information, and even query declarations.<br />
2 Relationships: This corresponds to the elements found in the<br />
descriptor file and applies to entity beans using CMP only. This is where containermanaged<br />
relationships are spelled out.<br />
3 Assembly Information: This corresponds to the element<br />
which explains how the beans interact with the application as a whole. Assembly<br />
information is broken down into four categories:<br />
■<br />
■<br />
Security Roles: simple definitions of security roles used by the application. Any<br />
security role references you defined for your beans must also be defined here.<br />
Method Permissions: each method of each bean can have certain rules about<br />
their execution. These are set here.<br />
128 BES Developer’s Guide