I have the following scenario:
Many employees can share the same address.
For which i have the following POJO classes:
1. Employee class that has properties name, designation of
String type and address of Address type.
2. Address class that has properties homeNum, sector and block of String type.
The below is the Employee and Address POJO class:
The below is the employee.hbm.xml file:
Some part of application code:
From the above code ishwar and abhijeet both share the same address. In this case there are 2 rows get added in the Employee table
and 1 row added in the Address table.
My question is that when I delete a employee using session.delete(employee) from the appliaction code. then from the Employee table a record for that employee get deleted and also its address entries from the Address table too get deleted. while another employee still has a reference of that address in the Employee table.
How can i prevent the address record not to get deleted from the Address table , if some employees have references of it in Employee table, when an employee is deleted.