An interesting article Of Persistence and POJOs: Bridging the Object and Relational Worlds, by Rod Johnson and Jim Clark in Mastering J2EE Application Development Series on OTN (the Oracle Technology Network) discusses how J2EE applications need to bring a Java based webapplication (or more particularly its Model component) together with a relational database.
Step 9: Mastering Server-Side Java (Part 2)
In this installment of “Mastering J2EE Application Development,” we’ll look at two different (but complementary) frameworks that can work together or independently to help you overcome the complexity of accessing persistent data in J2EE applications, specifically:
* Oracle TopLink, a powerful object-relational persistence framework that provides object-oriented applications with a highly flexible, productive mechanism to access relational data
* The Spring Framework, a leading open source J2EE application framework, published under the Apache Software License. Spring provides services for all architectural tiers, but is particularly strong with respect to persistence by providing a consistent approach to data access. As you’ll see, Spring’s persistence services layer encompasses an implementation of the Data Access Objects (DAO) J2EE design pattern.
Using TopLink and Spring’s DAO layer together can offer a high-performance, productive approach to persisting Plain Old Java Objects (POJOs)â€”that is, normal Java objects that are neither JavaBeans, nor Entity Beans, nor Session Beansâ€”to relational databases.
The article presents an example of using Toplink with Spring and also provides source code of adapter-classes that integrate Spring with Toplink:
Now available on OTN, the Spring/TopLink integration builds on the consistent architectural pattern established by Spring’s integration with other ORM frameworks. The Spring-TopLink integration code was written by the Oracle TopLink team, but is likely to be donated by Oracle to the Spring project. Both Oracle and the Spring community plan to support users of the integration.
Spring-TopLink integration enables you to enjoy a consistent programming model whether you use TopLink inside or outside an application server. The Spring TopLink integration includes:
* Convenience classes, such as TopLink template, that make many TopLink operations very easy and provide simplified model for implementing more complex operations by eliminating resource lookup.
* Exception translation utilities, that can translate TopLink exceptions into Spring’s DataAccessException hierarchy.
* Integration with Spring transaction management A proof-of-concept application, PetClinic, demonstrates the integration and will help get you started with Spring and TopLink. Although PetClinic is a simple application, it illustrates some important best practices, and can serve as an architectural template for much sophisticated use of Spring and TopLink.
An interesting side-note on EJB 3.0 – On the Horizon: What about EJB 3.0?
The Enterprise JavaBeans (EJB) 3.0 specification, currently being developed through the JCP as JSR-220, will include a POJO persistence specification that will effectively render the existing entity bean model obsolete. This initiative has also led to some uncertainty in the O-R mapping space.
Nonetheless, if your application can benefit from O-R mapping, you should adopt an ORM tool now, and enjoy the resulting productivity gains. If you choose a leading product, such as Oracle TopLink, Hibernate, or Kodo JDO, you can be sure that the vendor will provide a migration strategy to JSR-220 POJO persistenceâ€” you may well be using the same tool now in two years time, but simply through a different API. (Migration from EJB 2.x entity model to the JSR-220 POJO persistence will be more difficult.)
Furthermore, the EJB 3.0 specification is not due for release until early 2006â€”in the meantime, it’s vital to have a viable, productive O-R mapping solution.