Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Hibernate

You're reading from   Mastering Hibernate Learn how to correctly utilize the most popular Object-Relational Mapping tool for your Enterprise application

Arrow left icon
Product type Paperback
Published in May 2016
Publisher Packt
ISBN-13 9781782175339
Length 204 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

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: Another way to relate two tables is by creating a join table that will have at least two columns that store the primary keys of the rows that should be related. This is typically used for 1:M and M:N relationships. Both columns should be NON-NULLABLE...
You have been reading a chapter from
Mastering Hibernate
Published in: May 2016
Publisher: Packt
ISBN-13: 9781782175339
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image