Mapping concepts
Mapping objects to relations is the core mission of Hibernate, and as we discussed previously, this can be a difficult challenge that can only be overcome by understanding the fundamental concepts.
Let's explore mapping concepts by reviewing some of the fundamentals of relational databases, such as relational algebra, simple and composite IDs, join tables, and foreign keys.
Instances and rows
The origin of relational database concepts is Relational Algebra, which is based on Set Theory. Just as we think of objects as instances of classes, you should also think of a database row (a tuple) as an element of a set (the relation) that is defined by the database tab.
For example, if your object graph contains an instance of the Person
entity class that represents John
and another instance that represents Sara
, you should think of these as two rows in the Person
table.
In both cases, by being an instance of a class or a row of a table, they agree to possess certain attributes...