Consider as an example that your data model could contain the following entities: Company, Individual, Party and Product. With Talend Studio, you can define inheritance types where Individual and Company both extend Party. Party becomes a polymorphic element that holds individuals and companies.
You can also define in the Product entity a foreign key in the supplier attribute that points at the Party entity. So, this foreign key can also point at Individual or Company since both extend Party, so it acts as a polymorphic foreign key.
Before you begin
You have already created your data model. For further information, see Creating a data model.
About this task
To create inheritance and polymorphism for entities, proceed as follows:
- In your data model, create the business entity Party selecting the Complex type and Sequence options with a newly created complex type PartyType. For further information, see Creating business entities in a data model.
Expand Party and its group type, right-click the
by-default element and then select Edit Element from the
A dialog box pops up.
- Change the name to code and then click OK to close the dialog box.
Create the business entity Company selecting the
Complex type with a newly created complex type
CompanyType which extends the existing complex type
This will add the PartyType as a group type below Company. Here, you have defined inheritance between the Company and Party entities where Company extends Party.
- Expand Company and its group type, and then change the by-default element to name. You will only need a name for the company.
- Do the same to define inheritance between the Individual and Party entities where Individual extends Party.
- Define two attributes in the group type of the Individual entity: firstName and lastName. You will need these two elements for an individual.
- Create a Product business entity selecting the Complex type and All options.
- Add two new elements id and name to the Product entity.
What to do next
Your data model should look like the one shown below:
The Company and Individual entities extend the Party entity using the PartyType group. All complex types are also listed in the Data Model Types panel.
Now, you can create a polymorphic foreign key which, by pointing to the Party entity, can also point to the Individual or Company entities, since both extend Party.
Create a supplier attribute in the Product entity.
Right-click supplier and select Set the Foreign Key from the list.
A dialog box pops up.
Click the three-dot button and browse to set an Xpath to the entity to which you want the foreign key to point. In this example, the Xpath is set to Party/code.
Click Add and then OK.
The foreign key path is listed below the supplier attribute.
You have achieved inheritance here at the entities level by adding the Party group type to the Company and Individual entities.
Polymorphism is also achieved when, at runtime, the actual Party element can be expanded into Individual or Company when a business user tries to create a data record through Talend MDM Web UI. Business users will also have access to a foreign key list that displays Individual and Company when they click the Select the relationship icon. From this list they can choose any of the extended types you defined in Talend Studio.
By default, the complex types list displays the code of the types, but Talend Studio also lets you define labels for the complex types so that they can have labels in different languages and become more understandable as displayed in the Select a type list. To do so, proceed as follows:
Open the data model where you have defined the complex types.
Click Schema Source at the bottom of the editor to open the source XML schema of the data model.
Browse to the schema corresponding to the extended complex type to which you want to add a label and which you want to display in a certain order for the business user.
Inside the root element of the complex type, use the
X_Label_<ISO>annotation to add a label for the extended type as follows:
... <xsd:complexType name="IndividualType"> <xsd:annotation> <xsd:appinfo source="X_Label_EN">individual supplier</xsd:appinfo> <xsd:appinfo source="X_Label_FR">fournisseur individuel</xsd:appinfo> </xsd:annotation> <xsd:complexContent> ...
In the above schema, you want to name the IndividualType as individual supplier and you want it to be the third in the list of extended types.
Save your modifications in the model editor.
When authorized business users browse master data records in the updated data model through Talend MDM Web UI, the Select the relationship icon gives them access to the extended type list that shows the labels you defined in the annotation elements.