Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic doubt in hibernate mapping for one-to-many and many-to-one

 
Chaitanya Rach
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Hibernate and learning using the hibernate documentation and going through the one-to-many and many-to-one associations without using Join tables. The document says that:

Many-to-One

A unidirectional many-to-one association is the most common kind of unidirectional association.

One-to-Many

A unidirectional one-to-many association on a foreign key is an unusual case, and is not recommended.

Why the document recommends not use one-to-many associations?

Also the document says that the association for many-to-one with join table is used when the association is optional. What does it mean when it says the association is optional?

Many-to-one

A unidirectional many-to-one association on a join table is common when the association is optional.

Please help me in understanding the concepts.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chaitanya Rach wrote:Why the document recommends not use one-to-many associations?

They are saying it is better to have a bi-directional relationship in this case. It's unusual to have a scenario where you have a one-to-many relationship where the "many" side wouldn't benefit from knowing which "one" it is related back to.

Chaitanya Rach wrote:Also the document says that the association for many-to-one with join table is used when the association is optional. What does it mean when it says the association is optional?

It's more like a "many to zero" relationship.

ps - I gave you a cow for asking specific questions based on the documentation. It's an excellent way to ask a question because it shows what you already know.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic