Question on TargetPerEntity Inheritance and Save

Posts   
 
    
amitjindal
User
Posts: 34
Joined: 03-Jun-2010
# Posted on: 18-Aug-2010 10:44:40   

Hello,

We have a inheritance hierarchy in database: Party Person (Inherits from Party) Employee (Inherits from Person) PayrollEmployee (Inherits from Employee)

Now we are doing a composable application that decides at runtime what modules are present and accordingly the form shown contains just Employee or Employee and Payroll Employee. The save button needs to now save both.

So for test code, we first save Employee, then PayrollEmployee in which we specify the same Guid and Employee object. However we get exception of Primary Key violation. Obviously the PayrollEmployee is trying to create a new hierarchy and GUID is same.

So is there a way to use the hierarchy and still be able to save both in sequence. We do need to save both as the Employee module cannot know if Payroll module is present or not. So Employee module is only doing its part. It is the payroll module which is dependent on Employee and need to adjust for the difference.

Please suggest.

Amit Jindal

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Aug-2010 16:38:03   

This surely will cause a PK violation. As saving a child entity will also attempt to save it's parent entity first.

In your case you should pass the root class (Party entity) to the saving routine, and thanks polymorphism any object which inherit from the root class directly or indirectly will get saved correctly along with all its parent entities.

Only thing you should do, is to move the saving routine outside the composable modules.