RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Simplify Java Object Persistence with Hibernate : Page 5

The 'impedance mismatch' between relational databases' tabular orientation and object-oriented Java's hierarchical one is a perennial problem for which the Java world has several good solution offerings. The second in a three-part series, this article examines the ways that the Hibernate framework attempts to simplify the chore of connecting relational databases and the Java programming language.

The Data Tier
Each business-service request is passed to the appropriate business service for processing. A business service performs the necessary business logic and makes use of the appropriate DAO for data-store access. Each DAO performs the necessary interactions with Hibernate in order to act upon a given data store. The UserDAO interface defines the methods each DAO must implement.

The UserDAO Interface

package com.jeffhanson.datatier;

import com.jeffhanson.businesstier.model.UserInfo;

public interface UserDAO
   public UserInfo createUser(String id,
                              String fullName,
                              String address,
                              String city,
                              String state,
                              String zip)
      throws DAOException;

   public UserInfo readUser(String id)
      throws DAOException;

   public UserInfo[] readUsersByState(String state)
      throws DAOException;

   public void updateUser(UserInfo userInfo)
      throws DAOException;

   public void deleteUser(UserInfo userInfo)
      throws DAOException;
An implementation of the UserDAO interface enables access to the UserInfo object's data store, and is provided by the HibernateUserDAO class (see Listing 4).

Closing the Gap
The architectural differences between Java object hierarchies and relational database tables make the task of persisting Java object data to and from relational databases quite daunting for developers. The "impedance mismatch" between relational tables and Java object hierarchies has led to the development of several different object-persistence technologies attempting to close the gap between the relational world and the object-oriented world. The Hibernate framework defines an object/relational mapping mechanism and query language that makes storage and retrieval of Java objects to and from a data store a relatively simple proposition.

Jeff Hanson has more than 18 years of experience in the software industry. He has worked as senior engineer for the Windows OpenDoc port and as lead architect for the Route 66 framework at Novell. He is currently Chief Architect for eReinsure, which specializes in providing frameworks and platforms for J2EE-based reinsurance systems. Jeff has also authored numerous articles and books.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date