Comprehensive study EJB 2.0 (2)

zhaozj2021-02-08  216

Comprehensive study EJB 2.02001-04-05 · - · WSDN

The CMP model in EJB 1.1 is in EJB 1.1, the Bean developers are responsible for declaring the Persistent field of the BEAN class as the Java basic type or sequential type. The following example shows an Employee enterprise-class bean class, which is defined by EJB 1.1, with several CMP fields: // Employee Bean PUBLIC CLASS EMPLOYEEBEAN IMPLEments JAVA.EJB.EntityBean {// Instance Field EntityContext EJBCONText; File: field container-managed public // int identity; public String firstName; public String lastName; public double salary; public address address; public Integer ejbCreate (int id, String fname, String lname) {identity = id; firstName = fname; lastName = Lname; return null;} ... // address from the belonging class PUBLIC CLASDRESS IMPLEMENTS SERIALIZABLE {Public String Street; Public String City; Public STRING STATE; Public String Zip;} When the relational database is used for persistence, the basic field such as Identity, Firstname, LastName and Salary are easy to persist because they are well mapped to SQL types such as Integer, Char, and Double. In EJB 1.1, the XML deployment descriptor of the CMP bean provides a CMP-field element to identify persistence fields in this bean class (the fields managed by the container management). As shown below, the cmp-field element is used to distinguish the fields written to the database and the fields that do not write to the database. For example, the EJBContext field is not included in the list of fields managed by the container, so it is not a persistent field.

Employeejb ... container ... Identity firstname lastname Salary address address ... The container provider provides a tool to map the Persistence field of the BEAN to the column in the database table, usually each bean corresponds to a table. However, the type of semicamination, such as Address, is more difficult to persist. In EJB 1.1, there is no standard method to map sequentially to the relational database. Although the Address class has its own field set, the XML deployment descriptor does not provide a mechanism to map these fields to the database. In most cases, it is desirable to persist in a database table in a binary type (such as address) as a binary type (sometimes referred to as a BLOB type). This problem has also become serious because the data scheme of the entity bean is gradually complex. For example, Employee Beans may have multiple sub-objects similar to Address, such as Benefits and JobPosition. These sub-objects are called slave objects, which can form complex object maps across several tables in a relational database. In addition, the CMP in EJB 1.1 is largely insufficient to persist with other beans. In EJB 1.1, if a bean is ready to maintain a relationship with another bean, the container will automatically use the primary keyword or handle as a link. The relationship with some other beans may be two-way, or to rely on some fields that are not easy to use by the master keyword or handle, in order to maintain the relationship with such beans, the above method has proven to be a far Unmine mechanism. EJB 2.0 CMP Model In EJB 2.0, the new contract between the CMP entity bean and the Persistent Manager enables you to define more complex and more portable relationships in entity beans, including BEAN and Bean The relationship between the bean and the slave object, even between the object and the slave object. Persistent Manager is new to Enterprise JavaBeans deployment procedures.

转载请注明原文地址:https://www.9cbs.com/read-2708.html

New Post(0)