Hibernate Many to Many Example using Annotation
In the previous section, we have performed many to many mapping using XML file. Here, we are going to perform this task using annotation.
We can map many to many relation either using list, set, bag, map etc. Here, we are going to use list for many-to-many mapping. In such case, three tables will be created.
Example of Many to Many Mapping
In this example, we will generate a many to many relation between questions and answers by list.
1) Create the Persistent class
2) Add project information and configuration in pom.xml file.
Open pom.xml file and click source. Now, add the below dependencies between <dependencies>....</dependencies> tag.
3) Create the configuration file
This file contains information about the database and mapping file.
4) Create the class to store the data