Hibernate Many to One Mapping using XML
In numerous to one mapping, different credits can be alluded to one trait as it were.
In this precedent, each worker has one organization address just and one location has a place with numerous representatives. Here, we will perform numerous to one mapping utilizing XML.
1) Persistent classes for balanced mapping
There are two tenacious classes Employee.java and Address.java. Representative class contains Address class reference and bad habit versa.
2) Mapping files for the persistent classes
The two mapping files are employee.hbm.xml and address.hbm.xml.
- <?xml version='1.0' encoding='UTF-8'?>
- <!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 5.3//EN"
- <class name="com.javaocodegeeks.Employee" table="emp22">
- <id name="employeeId">
- <generator class="increment"></generator>
- <property name="name"></property>
- <property name="email"></property>
- <many-to-one name="address" cascade="all"></many-to-one>