Java Reference
In-Depth Information
public class Customer {
int customerId;
int customerReference;
String name;
Set email;
}
So, you should add another question: can a customer have more than one e-mail address?
The set could contain a single entry, so you can't automatically infer that this is the case.
The key questions from the previous options are as follows:
Q1 : Can an e-mail address belong to more than one user?
Q2 : Can a customer have more than one e-mail address?
The answers to these questions can be formed into a truth table, as in Table 5-4.
Table 5-4. Deciding the Cardinality of an Entity Relationship
Q1 Answer
Q2 Answer
Relationship Between Customer and Email
No
No
One-to-one
Yes
No
One-to-many
No
Yes
Many-to-one
Yes
Yes
Many-to-many
These are the four ways in which the cardinality of the relationship between the objects
can be expressed. Each relationship can then be represented within the mapping table(s) in
various ways.
The One-to-One Association
A one-to-one association between classes can be represented in a variety of ways. At its sim-
plest, the properties of both classes are maintained in the same table. For example, a
one-to-one association between a User and an Email class might be represented as a single
table, as in Table 5-5.
Table 5-5. A Combined User / Email Table
ID
Username
Email
1
dcminter
dcminter@example.com
2
jlinwood
jlinwood@example.com
3
tjkitchen
tjkitchen@example.com
The single database entity representing this combination of a User and an Email class is
shown in Figure 5-4.
Search WWH ::




Custom Search