Association cardinality
Just as relational databases define the cardinality of table relationships, ORM solutions also define the cardinality of entity associations. Before we discuss how to map associations, let's review how associations are created in a relational database. The following are the two types of relationship:
- Foreign key relationship: You can relate a table to another by declaring a column as a foreign key of the other table. This is typically used for a 1:1 (one-to-one) or a M:1 (many-to-one) relationship. If you make the foreign key column UNIQUE, then you are defining a 1:1 relationship; otherwise, this is M:1. If you make it NULLABLE, then the relationship is optional; that is, 1:0, 1:1, M:0, or M:1.
- Join table relationship:
Get Mastering Hibernate now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.