Java Reference
In-Depth Information
Figure 5-4. A single entity representing a one-to-one relationship
Alternatively, the entities can be maintained in distinct tables with identical primary keys,
or with a key maintained from one of the entities into the other, as in Tables 5-6 and 5-7.
Table 5-6. The User Table
ID
Username
1
dcminter
2
jlinwood
3
tjkitchen
Table 5-7. The Email Table
ID
Username
1
dcminter@example.com
2
jlinwood@example.com
3
tjkitchen@example.com
It is possible to create a mandatory foreign key relationship from one of the entities to
the other, but this should not be applied in both directions because a circular dependency
would be created. It is also possible to omit the foreign key relationships entirely (as shown
in Figure 5-5) and rely upon Hibernate to manage the key selection and assignment.
Figure 5-5. Entities related by primary keys
Search WWH ::




Custom Search