Java Reference
In-Depth Information
CHAPTER 5
n n n
An Overview of Mapping
T he purpose of Hibernate is to allow you to treat your database as if it stores Java objects.
However, databases in practice do not store objects—they store data in tables and columns.
Unfortunately, there is no simple way to correlate the data stored in a database with the data
represented by Java objects.
The difference between an object-oriented association and a relational one is fundamen-
tal. Consider a simple class to represent a user, and another to represent an e-mail address, as
shown in Figure 5-1.
Figure 5-1. An object-oriented association
User objects contain fields referring to Email objects. The association has a direction—
given a User object, you can determine its associated Email object. For example, consider
Listing 5-1.
Listing 5-1. Acquiring the Email Object from the User Object
User user = ...
Email email = user.email;
The reverse, however, is not true. The natural way to represent this relationship in the
database, as illustrated in Figure 5-2, is superficially similar.
Figure 5-2. A relational association
79
Search WWH ::




Custom Search