More object relational mapping
Book review Although it sounds like something to do with electrical resistance in AC circuits, "impedance mismatch" describes the issues that arise when dealing with the different conceptual bases of object oriented development and relational databases.
Developers model their domain with classes and objects, but when it comes to persisting these objects there's usually a relational database as the data store – which means having to stuff those nice object hierarchies into relational tables.
For very small applications, hand-coding provides an answer – a bit of SQL and some code can work wonders. Anything bigger requires an object-relational mapping (ORM) layer to bundle objects into and out of those relational tables.
While there's a certain satisfaction in rolling your own ORM layer, the fact is that there are plenty of powerful open-source ORM frameworks, and in the Java world, at least, Hibernate is one of the best known and most widely used.
Hibernate provides a complete persistence and query framework – basically you can code your application using plain old Java objects (POJOs), and then use Hibernate to marshal your objects, persist them to a back-end database of your choice, apply queries to the data, retrieve and instantiate the object tree and so on. It requires minimal change to your existing code, but does depend on building a suitable mapping from objects to tables and fields.
However, Hibernate isn't magic, there are configuration files to create, mappings to perform, and other bits of plumbing in order to make things work as seamlessly as you would like. Hence Beginning Hibernate by Dave Minter and Jeff Linwood, which aims to help the new user to get up, running, and productive quickly.
Unfortunately, setting up Hibernate is not simply a drag and drop affair – there are too many variables and dependencies involved in mapping from objects to databases. Some of these are explored in the opening chapter, including the relationship between Hibernate and the more traditional JEE use of enterprise Java beans (EJB) for persistence, and also touches on the latest EJB 3.0 release, which has incorporated some of the features of Hibernate.
The second chapter, covering integration and configuration, looks at the different ways of creating the mapping between Java objects and the underlying database. The advantages and disadvantages of properties files, XML files and Java annotations are all explored.
It's only in chapter three that the first sample application is built – although it feels like over-kill in that it uses Hibernate, the Hibernate tools, Ant, the HSQLDB database and logging. On the plus side, it's a realistic example of what you'd need to do in a real application. The downside is that it's fairly complex for a first look at Hibernate in action.
From then on the material gets more focused, and covers in greater detail the intricacies of mapping (both with XML and with the newer annotations), the use of the HQL query language, the filtering of search results, transactions, and the session object. Appendices include coverage of the advanced features (stored procedures, events and more), the Hibernate tools (Eclipse plug-in and Ant tasks), Hibernate and Spring also gets an appendix chapter, as does the process of upgrading from version 2.x to the latest 3.2 version.
While this is a book that's clearly designed for the Hibernate beginner, it's not for the Java beginner. The content is focused, technical, and heavy on the sample Java and XML code.
Verdict: It's not a light read, but then this isn't a topic that makes for light reading in the first place.
Author: Dave Minter and Jeff Linwood
List Price: £27.99
Buy this book at Register Books at Reg Developer's special discounted price! ®
Sponsored: RAID: End of an era?