Select JDO or CMP?
Translated from Http://www.onjava.com/pub/a/onjava/2003/05/21/jdo.html
Author: David Jordan and Craig Russell author of "Java Data Objects" book May 21, 2003
Author Note: The EJB of JDO and CMP mode is currently developing forward, but different routes are taken. JDO's core idea is to store traditional Java objects in different levels of the enterprise application architecture, and the CMP scheme is based on container environments and for special needs.
The difference between the two has become the topic of the controversy. You can see this controversy on jdocentral.com, and in mid-June 2003 Javaone conference, there will be some demonstrations and explanations to compare these two different technologies.
At this Javaone conference, 3368 technical dialogue will discuss the feasibility and practical experience of JDO and Struts (open source software for famous web application architecture design); 3236 topics research JDO and EJB container combination; 1289 topics The application mode is used in development when using JDO, JDBC, and EJB.
Chapter 17 of our "Java Data Objects" has a small paragraph describing the balance point of JDO and CMP. - Craig Russell
JDO is also CMP?
CMP entity beans and JDOs are worth considering before you decide under the project development strategy.
JDO is very suitable for crude particle size and fine grain size data object design, which is generally used in SessionBeans in an application server environment. CMP is also used for SessionBean, its remote call is rarely used.
The class written by JDO is only necessary to be used in any layer in the distributed architecture, and can be tested in a single layer or two layers before integrated into the web or application server. The CMP can only be debugged after posting to a specific application server.
JDO does not directly define remote behaviors, this is different from servlet, JSP, and EJB components. All distribution processes, transactions, and security policies are based on standalone storage managers, which is responsible for handling all class instances in your object model. This also shows that you can use JDO on any level in a distributed environment, while its remote behavior is implemented by the container, not JDO vendors.
The CMP component provides higher portability, Bean classes and descriptors are standardized. Most incompatibility only exists in the specification, including how to map classes to specific databases (not limited to relational databases), similar to read-only class options, other manufacturers extension. JDO products vary depending on the optional features supported by specific manufacturers.
In CMP, the relationship between objects is controlled, that is, the change in one end affects the other end and is visible to the application. JDO does not support the management of relationships, just some vendors provide similar functions in an extended manner.
Inheritance is a conceptually used for real object modeling, but CMP does not support it. CMP is inconsistent with the definition and implementation of the component. When implementing an EntityBean interface, the implementation of the category can have inheritance, but it is not possible when defining this EntityBean. The relationship between classes is just between the interfaces, not between the classes, so these relationships do not exist. For example, a CMP bean class called MediaItem cannot contact the class named MediaContent, because MediaContent is abstract, and there is no specific instance. To establish such a connection, you can only convert it to two relationships: one is MediaITEM and MOVIE class, one is the ModiaItem and Game class, and in each related method, you must take the two relationships. On the access object properties, CMP and JDO are also different. In the CMP bean, all attributes and object relationships are defined as an abstract GET and SET methods in the descriptor, and access to the actual attribute can only be done by the implementation class generated by the relevant tool. In JDO, saved attributes and relationships are declared in the descriptor, and these properties can be accessed directly, including the code generated by JDO products. The JDO booster will modify these code as appropriate when enhanced.
JDOQL and EJBQL provide similar methods for query data. Both can query and access data objects in the program, take "read-change-write" strategy, are not a complete data manipulation language (such as no data update statement), they are only used to find data objects and Access in the code.
CMP requires all access operations in the transaction environment, non-transactional access is not supported. JDO allows you to decide whether to use a transaction. For places where you need to update the data, JDO requires transactions, but just read code, including buffer, JDO supports non-transactional access.
Table 17-1 is a comparison of CMP beans and JDO storage classes
Table 17-1 Comparison of CMP Beans and JDO
Features CMP Beansjdo can store the enumeration of portability. Basic can be used. Few negative impact of the specifications definitions can be portable, two, web servers, application servers can store independence relative to the environment. Low: The class must implement the EJB interface and perform high in the EJB container: Class does not need to implement any specific interface, can perform metadata tags in any environment to store the descriptor indicate all storage type. Data indicates that all storage class tags can store properties Release Descriptor Mark All storage attributes and relational metadata default most storage properties and relationships (Simple) modeling objects CMP beans (Abstract underlying database ) The inheritance of the stored domain class does not support full support attribute access to abstract access, including direct access and GET / SET method Collection, SET support supports List, Array, MAP does not support optional functional relationships Reference to refer to CMP local interface refer to reference polymorphism of JDO storage class or interface does not support support programming query language Similar to SQL EJBQL based JDOQL remote method call support does not support life cycle management requirements setEntityContextunsetEntityContextejbActivateejbPassivateejbLoadejbStoreejbRemove no-argument constructor (can be private of) optional callback method ejbCreateejbPostCreateejbFind jdoPostLoadjdoPreStorejdoPreClearjdoPreDelete relational mapping vendors related companies related methods security policy Affairs policy support does not support the method does not support non-standard class non-transactional access support needed / Interface EJBLOCALHOME, local interface (if supported local access) EJBHome, remote interface (if remote access) The abstract class must implement the EntityBean identity class (if not the original type) can store the class identity class (only for custom ID) Transaction synchronous callback Support for David Jordan has created Object Identity, Inc., providing Java Data Objects (JDO) consultation and training services. David is also one of the author of the book of Java Data Objects, and the other author is Craig Russell.
Craig Russell is a JDO specification leader of Sun Microsystems.
O'Reilly and its association have recently (April 2003) published "Java Data Objects".
Chapter 1 Overview, you can download you can also download the book's directory, index, and full description of the above two parts: 9CBS version, or JavaResearch version (translated by Sun Guest) More information or purchase the book, please see Here.
The copyright of this article belongs to the author, but welcome to reprint, the premise is to indicate the source and the original. In addition, welcome
See some of my articles in my column, and make valuable comments!