user341215
user341215

Reputation: 9

Hibernate associations

what are the minimum tables I need for many to many associations in Hibernate?

Upvotes: 0

Views: 435

Answers (2)

Pascal Thivent
Pascal Thivent

Reputation: 570285

By design, relational databases management systems only support one-to-many relationships. The only way to represent physically a logical many-to-many relation between A and B is thus to introduce a third junction table AB with two one-to-many relationships A -> AB <- B where the primary key of AB is formed from the two foreign keys (i.e. values that are primary keys in A and B).

So to summarize, you need 3 tables. Below an illustration of the famous Order / Product samples:

alt text http://www.about-access-databases.com/images/many_to_many.jpg

Upvotes: 1

P&#233;ter T&#246;r&#246;k
P&#233;ter T&#246;r&#246;k

Reputation: 116246

Apart from the tables for the entities you want to associate, you need an association table. In its simplest form, it would contain only two foreign keys, one for each of the entities.

Upvotes: 1

Related Questions