Search code examples
hibernatecollectionshibernate-mapping

What is the use of collection mappings and association mappings?


I am working On Hibernate With Spring

If first i created database and i used Hibernate DAOs layer along with DAOsImpl.

and i simply mapped my model classes to database tables with simple mapping.then what is the use of Collection Mapping,Association Mapping????

without collection mapping and association mapping i can do my work whatever i want.

please give me any good explanation.


Solution

  • When you are mapping your model classes you are mapping the entities to the database, specifying types of fields, primary keys ...

    But when you are using Collection mapping you are defining the way these entities are related to each others, you are simply mapping the relationships/associations between entities. (specifying foreign keys, join tables, ...).

    Take a look at the Collection mapping Documentation for further information.

    For example for the given association:

    enter image description here

    You need Collection mapping to specify the type of relation between an author and a book.