Other Java/Database Integration Solutions
Hibernate represents merely one approach to object/relational mapping. Other programming languages and platforms offer a variety of other options, some similar to Hibernate, others radically different. Focusing on the Java world, here are a few of the popular alternatives.
Enterprise JavaBeans (EJB) 2.X
At the core of the J2EE specification, EJB 2.X attempts to provide a much broader set of features and functionality than Hibernate, at the price of a less robust core persistence model. The portion of J2EE/EJB 2.X most comparable to Hibernate is called container-managed entity persistence (CMP). Typically, CMP describes a system in which the J2EE server manages a single-entity bean class per table with individual-entity bean objects representing individual records. Conceptually, entity beans managed by the J2EE server include sophisticated functionality, such as complex transaction management, distributed caching, and much more. The alternative is bean-managed persistence, in which developer code is used to handle interaction with a database.
While EJB 2.X is suitable for certain large-scale enterprise applications, some developers find it difficult to work with. Most EJB 2.X systems involve a considerable amount of code generation and the need to master a complex suite of terminology. In particular, the implementation of the container-managed persistence layer and other components varies greatly between different application servers, making migration between projects that rely on container-managed persistence difficult. A popular use of Hibernate is as a persistence layer while working within the larger EJB 2.X environmentin effect, Hibernate serves as a replacement for container-managed persistence while leveraging the other portions of the EJB 2.X specification. This allows you to take advantage of many of the powerful features of your J2EE server without worrying about the portability of your object/relational layer.
Enterprise JavaBeans (EJB) 3.0
With an early draft specification first released in mid-2004, EJB 3.0 promises a persistence mechanism very similar to Hibernate. This is not surprising; the key developer of Hibernate was heavily involved in crafting the EJB 3.0 specification. Throughout this text, areas of similarity between EJB 3.0 and Hibernate will be highlighted, and additional comparison is provided in Chapter 13.
Java Data Objects (JDO)
Java Data Objects, or JDO, differ more from Hibernate in terms of implementation than from the interface offered to developers. Specifically, JDO normally requires compile-time pre-processing of the Java byte-code in order to add persistence capability, whereas Hibernate performs similar tasks at runtime when the application is first started. There are also differences in the APIs used to query from the persistence source. In particular, JDO attempts to solve a larger issue of persistence, targeting data stores other than relational databases. The attempt to target a broader range of storage mechanisms leads to a different focus than the relational database-focused Hibernate, with a different set of query capabilities. It's unclear whether the goal of targeting nonrelational database persistence engines is worth the tradeoffs.
As of this writing, there has been some discussion of future versions of Hibernate and JDO moving closer together. Hibernate already supports three different interfaces (ODMG, HQL, and Criteria). It's entirely possible that future Hibernate releases may support a JDO style interface as well.
As of this writing, JDO implementations include:
TJDO, or TriActive JDO, is an open-source implementation of the JDO specification. It is explicitly designed to operate as Java persistence layer. In other words, the developer is expected to focus on Java development, with the database schema generated and managed by TJDO. It is not appropriate for situations with an existing schema. For more information, see http://tjdo.sourceforge.net/. JPOX is another open-source JDO implementation. Unlike TJDO, more emphasis is placed on both schema-centric and Java-centric development. For more information, see http://www.jpox.org/. JCredo provides a commercial implementation of JDO. A free edition is available for download from the Web site at http://www.jcredo.com/. Apache OJB, available at http://db.apache.org/ojb/, provides both an ODMB and a JDO interface. Castor is an open-source data-binding framework. While the implementation doesn't adhere precisely to the Sun JDO specification, it's similar enough that someone familiar with JDO can easily use Castor. For more information on Castor, see http://castor.exolab.org/.
|
Q. What is container managed persistence, and what are Java data objects?
A. EJB 2.0 CMP is the part of the J2EE component model that provides an object persistence service for EJB Containers. CMP's goal is to provide a standard mechanism for implementing persistent business components. CMP is not a general persistence facility for the Java platform. CMP provides distributed, transactional, secure access to persistent data, with a guaranteed portable interface. CMP is based on a functional set/get data-access model. It does not support transparent Java instance variable persistence.
A. JDO is an architecture that provides a standard way to transparently persist plain Java objects. It is designed to work in multiple tiers of an enterprise architecture, including J2SE, Web tier, and Application Servers. It does not itself provide distributed objects, distributed transactions, or security services, although it might be integrated with an EJB container that provides these services. CMP is for persisting distributed components built specifically to the entity bean component API. JDO is geared toward local, rich object models not tied to any particular API. Developers can choose between these technologies by evaluating their requirements (persistent components or persistent objects).
- From Sun's EJB 2.0 CMP and JDO FAQ, http://java.sun.com/products/jdo/JDOCMPFAQ.html
|
Other Commercial O/R Tools
There are a variety of commercial object/relational tools, some of which were in existence long before Hibernate, EJB, or JDO. The prices for these tools range from free to tens of thousands of dollars. Options in this arena include Oracle's TopLink (http://otn.oracle.com/products/ias/toplink/) and Software Tree's JDX (http://www.softwaretree.com/).
|