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.