
Chapter 3 Creating a WebObjects Database Application
64
MOVIE_ROLE table having a MOVIE_ID column. In the MOVIE table,
MOVIE_ID is a primary key, while in MOVIE_ROLE it’s a foreign key.
A primary key is a column or combination of columns whose values are
guaranteed to uniquely identify each row in that table. For example, each row
in the MOVIE table has a different value in the MOVIE_ID column, which
uniquely identifies that row. Two movies could have the same name but still be
distinguished from each other by their MOVIE_IDs.
A foreign key matches the value of a primary key in another table. The purpose
of a foreign key is to identify a relationship from a source table to a destination
table. In the following diagram, notice that the value in the MOVIE_ID column
for both MOVIE_ROLE rows is 501. This matches the value in the
MOVIE_ID column of the “Alien” MOVIE row. In other words, “Ripley”
and “Ash” are both roles in the movie “Alien.”
Suppose you fetch a Movie object. Enterprise Objects Framework takes the
value for the movie’s MOVIE_ID attribute and looks up movie roles with the
corresponding MOVIE_ID foreign key. The framework then assembles a
network of enterprise objects that connects a Movie object with its MovieRole
objects. As shown below, a Movie object has a vector of its MovieRoles, and the
MovieRoles each have a Movie.
1
0
2
8
R
i
p
l
e
y
5
0
1
5
0
1
A
l
i
e
n
1
1
3
2
A
s
h
5
0
1
7
0
3
T
o
y
S
t
o
r
y
T
A
L
E
N
T
_
I
D
M
O
V
I
E
_
R
O
L
E
M
O
V
I
E
_
I
D
M
O
V
I
E
_
I
D
T
I
T
L
E
M
O
V
I
E
_
R
O
L
E
M
O
V
I
E
Comentarios a estos manuales