Chapter 7: ObjectRelational Mapping


Overview

We saw in the previous chapter how Spring supports transaction strategies and JTA transaction synchronization for a variety of Object-Relational mapping (O/R mapping) tools. Rather than providing its own O/R mapping implementation, Spring integrates with popular third-party solutions:

  • iBATIS SQL Maps (1.3 and 2.0): A simple but powerful solution for externalizing SQL statements into XML files, including result mappings and parameter mappings for JavaBeans. Does not aim to provide an object query language or automatic change detection.

  • Hibernate (2.1 and 3.0): A very popular open source O/R mapping tool, featuring its own textual object query language called HQL and dedicated support for detached objects. Uses snapshot comparisons for automatic change detection.

  • JDO (1.0 and 2.0): The JCP specification for general object persistence, focusing on byte code modification for on-the-fly change detection, in combination with a strict lifecycle for persistent objects. JDO 2.0 is about to introduce standard support for relational databases and detached objects.

  • Apache OJB (1.0): O/R mapping platform with multiple client APIs: PersistenceBroker, ODMG, and (through a plugin) JDO. Spring includes dedicated support for the PersistenceBroker API, which offers full-fledged mapping capabilities but does not aim to provide automatic change detection.

  • Oracle TopLink: Mature O/R mapping tool, originally from The Object People, now owned by Oracle. Offers very flexible mapping capabilities through the TopLink Workbench GUI. Uses snapshot comparisons for change detection on explicitly registered objects.

In this chapter, we will concentrate on iBATIS SQL Maps 2.0 and Hibernate 2.1 — two very popular persistence solutions, but with quite different approaches. While previous knowledge about those tools is not required, comprehensive coverage of either of them is outside of the scope of this chapter. We will instead introduce the basic principles and focus on usage in a Spring environment, as illustrated by our sample applications.

We will also discuss Spring's JDO integration, discussing the basic model and pointing out important similarities and differences to the Hibernate support, and Spring's TopLink support, to highlight the conceptual consistency within Spring's support for different O/R mapping frameworks. This conceptual basis shows how Spring will support JSR-220 persistence — the POJO persistence standard to be defined by the EJB 3.0 expert group — which is to be independent of the EJB 3.0 specification proper.

A full discussion of Apache OJB and Oracle TopLink is outside the scope of this book. The basic approach is similar to Hibernate and JDO, although there are differences in both semantics and features. Please refer to http://db.apache.org/ojb and www.oracle.com/technology/products/ias/toplink for further information on OJB and TopLink, respectively, and to the Spring reference documentation for information on how to integrate them into a Spring environment.

Note that all these strategies work within Spring's consistent DAO abstraction approach, allowing for mixed usage with Spring's own JDBC framework, and as far as possible also allowing for mixed usage of multiple O/R mapping strategies in the same application.



Professional Java Development with the Spring Framework
Professional Java Development with the Spring Framework
ISBN: 0764574833
EAN: 2147483647
Year: 2003
Pages: 188

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net