web server - Borland Technical Publications
web server - Borland Technical Publications web server - Borland Technical Publications
Container-Managed Persistence in Borland Enterprise Server Mapping CMP fields to multiple tables You may have an entity that contains information persisted in multiple tables. These tables must be linked by at least one column representing a foreign key in the linked table. For example, you might have a LineItem entity bean mapping to a table LINE_ITEM with a primary key LINE that is a foreign key in a table called QUANTITY. The LineItem entity also contains some fields from the QUANTITY table that correspond to LINE entries in LINE_ITEM. Here's what our LINE_ITEM table might look like: LINE ORDER_NO ITEM QUANTITY COLOR SIZE 001 XXXXXXX01 Kitty Sweater 2 red XL QUANTITY, COLOR, and SIZE are all values that are also stored in the QUANITY table, shown here. Note the identical values for some of the fields. This is because the LINE_ITEM table itself stores information in the QUANTITY table, using the LineItem entity to provide composite information. LINE QUANTITY COLOR SIZE 001 2 red XL Again, we can describe these relationships using a combination of elements and a element. The elements define the fields found in LineItem. Since there are some fields that require information from QUANTITY, we'll specify that generically by using a TABLE_NAME.COLUMN_NAME syntax. For instance, we'd define LINE_ITEM's COLOR column as QUANITY.COLOR. Finally, we'll specify the linking column, LINE, that makes up our primary key/foreign key relationship. We'll do this using the element. Now let's look at the XML. First we define the CMP fields for the LineItem entity bean: LineItem . . orderNumber ORDER_NO line LINE item ITEM quantity QUANTITY.QUANTITY color QUANTITY.COLOR size QUANTITY.SIZE Chapter 15: Entity Beans and Table Mapping for CMP 2.0 135
Container-Managed Persistence in Borland Enterprise Server Next, we specify the linking column between LINE_ITEM and QUANTITY by using a element. LINE_ITEM LINE QUANTITY LINE CASE 1: a unidirectional one-toone relationship. Specifying relationships between tables To specify relationships between tables, you use the element in ejbborland.xml. Within the element, you define an containing the role's source (an entity bean) and a element containing the relationship. The descriptor then uses elements to specify relationships between two tables, a and a . You must observe the following cardinalities: ■ One must be defined per direction; if you have a bidirectional relationship, you must define an for each bean with each referencing the other. ■ Only one element is permitted per relationship. Within the and elements, you specify a column list that contains the column names to be linked together. The column list corresponds to the element in the descriptor. The XML is: Let's look at some relationships to see how this XML is put into practice: Here, we have a Customer entity bean with a primary key, CUSTOMER_NO, that is also used as a primary key for an entity called SpecialInfo, which contains special customer information stored in a separate table. We need to specify a relationship between these two entities. The Customer entity uses a field called specialInformation to map to the SpecialInfo bean. We specify two relationship roles, one for each bean and assign either to left- and/or right-table. Then we specify the name of their related column for both. Customer specialInformation CUSTOMER CUSTOMER_NO 136 BES Developer’s Guide
- 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 and 138: 126 BES Developer’s Guide
- Page 139 and 140: Container-managed persistence and R
- Page 141 and 142: Container-Managed Persistence in Bo
- Page 143 and 144: Container-Managed Persistence in Bo
- Page 145: 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
- Page 189 and 190: JDBC API Modifications JDBC API Mod
- Page 191 and 192: Handling of EJB exceptions Applicat
- Page 193 and 194: 182 BES Developer’s Guide
- Page 195 and 196: Client View of an MDB Client View o
Container-Managed Persistence in <strong>Borland</strong> Enterprise Server<br />
Next, we specify the linking column between LINE_ITEM and QUANTITY by using a <br />
element.<br />
<br />
<br />
LINE_ITEM<br />
<br />
LINE<br />
<br />
<br />
<br />
QUANTITY<br />
<br />
LINE<br />
<br />
<br />
<br />
<br />
<br />
CASE 1: a<br />
unidirectional one-toone<br />
relationship.<br />
Specifying relationships between tables<br />
To specify relationships between tables, you use the element in ejbborland.xml.<br />
Within the element, you define an <br />
containing the role's source (an entity bean) and a element<br />
containing the relationship. The descriptor then uses elements to specify<br />
relationships between two tables, a and a . You must<br />
observe the following cardinalities:<br />
■<br />
One must be defined per direction; if you have a bidirectional<br />
relationship, you must define an for each bean<br />
with each referencing the other.<br />
■<br />
Only one element is permitted per relationship.<br />
Within the and elements, you specify a column list that<br />
contains the column names to be linked together. The column list corresponds to the<br />
element in the descriptor. The XML is:<br />
<br />
Let's look at some relationships to see how this XML is put into practice:<br />
Here, we have a Customer entity bean with a primary key, CUSTOMER_NO, that is also used<br />
as a primary key for an entity called SpecialInfo, which contains special customer<br />
information stored in a separate table. We need to specify a relationship between these<br />
two entities. The Customer entity uses a field called specialInformation to map to the<br />
SpecialInfo bean. We specify two relationship roles, one for each bean and assign<br />
either to left- and/or right-table. Then we specify the name of their related column for<br />
both.<br />
<br />
<br />
<br />
<br />
Customer<br />
<br />
<br />
specialInformation<br />
<br />
<br />
CUSTOMER<br />
CUSTOMER_NO<br />
<br />
136 BES Developer’s Guide