toring and retrieving information for most applications usually involves some form of interaction with a relational database. This has presented a fundamental problem for developers for quite some time since the design of relational data and object-oriented instances share very different relationship structures within their respective environments. Relational databases are structured in a tabular configuration and object-oriented instances are typically structured in a hierarchical manner. This "impedance mismatch" has led to the development of several different object-persistence technologies attempting to bridge the gap between the relational world and the object-oriented world. The Hibernate persistence framework provides yet another means for bridging this gap.
This article is the second in a series discussing how three different object-persistence technologies (EJB, Java Data Objects, and Hibernate) attempt to simplify the chore of connecting relational databases and the Java programming language.
Introducing Object Persistence
The task of persisting Java objects to a relational database is currently being facilitated by a number of different tools which allow developers to direct persistence engines in converting Java objects to database columns/records and back. This task involves serializing hierarchically-structured Java objects to a tabular-structured database and vice versa. Essential to this effort is the need to map Java objects to database columns and records in a manner optimized for speed and efficiency.
The Hibernate framework tackles the Java-object-to-database problem as elegantly as any framework currently available. Hibernate works by persisting and restoring plain old Java Objects (POJOs) using a very transparent and low-profile programming model.
An Overview of Hibernate
Hibernate is a Java framework that provides object/relational mapping mechanisms to define how Java objects are stored, updated, deleted, and retrieved. In addition, Hibernate offers query and retrieval services that can optimize development efforts within SQL and JDBC environments. Ultimately, Hibernate reduces the effort needed to convert between relational database result-sets and graphs of Java objects.
One of its unique features is that Hibernate does not require developers to implement proprietary interfaces or extend proprietary base classes in order for classes to be made persistent. Instead, Hibernate relies on Java reflection and runtime augmentation of classes using a powerful, high-performance, code-generation library for Java called CGLIB. CGLIB is used to extend Java classes and implement Java interfaces at runtime.