0

I have 2 tables. Employee and EmployeeDetails. Employee table has the basic details like Employee Id, Department and some audit fields like Created By, Created Timestamp. EmployeeDetails table has all the personal details about the employee and same audit fields (Created By, Created Timestamp) like Employee table. Now the audit fields and Version column are part of a MappedSuperclass ModelBaseFields.
I am using JOINED Inheritance in Employee which is my base class. It extends ModelBaseFields which is a MappedSuperclass. EmployeeDetails extends Employee.

Now the problem is, whenever I try to persist the data, Employee table INSERT query is formed properly however, EmployeeDetails INSERT query is missing audit fields (Created By, Created Timestamp) and version column.

I have tried using SINGLE TABLE inheritance with Secondary table. I am getting same issue in that scenario as well.

How do I add common columns in child table?

  • add the entity classes, lets see the code.. the most important bits – Maciej Kowalski Jul 27 '17 at 09:48
  • I don't understand your issue or what you are after. If EmployeeDetails is extending Employee, it will NOT include any of its fields in its table. Employee fields go in the Employee table. What you might be looking for is table per class inheritance, where the EmployeeDetails table duplicates and adds to the Employee table. But it sounds like you just want the audit fields, but I don't understand why you would need the audit fields in Both tables. Any row in EmployeeDetail will match up 1:1 with a row in Employee, so the audit fields will just be duplicate values anyway. – Chris Jul 27 '17 at 12:44
  • Maybe your model is wrong. Sounds like Employee should have a 1:1 to an EmployeeDetails class, where both extend ModelBaseFields – Chris Jul 27 '17 at 12:46
  • Hi Chris, Thanks.. I would try that.. – Shrey Bansod Jul 28 '17 at 09:45
  • @Chris I have one more question why wouldn't my child entity (Discriminator column class) EmployeeDetails cant inherit MappedSuperClass values while Employee class can.I'm using Inheritence type JOINED and discriminator for specifying class as per records in table – Shrey Bansod Jul 28 '17 at 12:45
  • It does inherit them, but follows java inheritance- the fields are there, and the columns too, they just are accessible through the Employee superclass, and so tied to the Employee table. Only properties specific to the EmployeeDetail class make it to the EmployeeDetail table with joined inheritance. – Chris Jul 28 '17 at 13:53

0 Answers0