Hi I am new to the Hibernate and JPA. I have done some basic tutorials but I am stuck with this problem where I need to create an entity which can take data from multiple tables and each table uses composite primary key.
In this example, companies can have multiple departments, each departments have multiple employees. Based on the department employees manage different contact numbers
For example support department employees have home number, mobile number and office number sales department employee can have only office number
Employee_Details table have following columns companyId, departmentId, employeeId, firstName, lastName (primary key - companyId, departmentId and employeeId ).
Employee_Contact table have following columns companyId, departmentId, contactTypeId, contactTypeName (primary key - companyId, departmentId and contactTypeId)
Contact_Details table have following columns companyId, departmentId, employeeId, contactTypeId, areaCode, number (primary key - companyId, departmentId, employeeId and contactTypeId)
What will be the best way to map these tables in an entity which can include employee firstName, lastName and a collection of contact details which include contactTypeName, areaCode, number
The database design is a bit weird, however it cant be changed and I have to work with it.
|