Javatpoint Logo
Javatpoint Logo

Hibernate Many to Many Example using XML

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 using list.

1) Create the Persistent class

There are two persistent classes and Question class contains Answer class reference and vice versa.

2) Create the Mapping file for the persistent class

Here, we have created the question.hbm.xml and answer.hbm.xml file for defining the list.



3) Create the configuration file

This file contains information about the database and mapping file.


4) Create the class to store the data


Hibernate Many to Many Example 1 Hibernate Many to Many Example 2


Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA