hibernate

What is the need for many-to-one mapping in hibernate?


Why don't we just specify the table name and column name? How specifying many-to-one helps in generating query?


Solution

  • Hibernate is an ORM tool. Object Relational Mapping. The tool needs to understand the relationships between classes.

    If you continue down your line of thought, why do we need to map one-to-many, or any other relationship?

    Lets say you have a class Child, many of which can be on instances of Parent. If your relationship is bidirectional, a child instance would have a reference to an instance of Parent.

    So if you loaded a child instance, hibernate needs to know how that child is related to its Parent.