4.2.3. Entity Inheritance

This section demonstrates how to use entity inheritance in CUBA applications.

Let’s assume that we have two types of clients - companies and individuals, which have some common attributes. We would like to store the common attributes in one table and use separate linked tables to store specific attributes.

So, the data model contains the Client entity, which is a base class stored in the SAMPLE_CLIENT table. The Company and Person entities are stored in separate tables with foreign keys that reference the base table.

The Order entity has a reference to Client. As the client can be of the different types, when users create orders, they should be able to choose the type of the client.

inheritance

Client.java entity:

  • Inheritance strategy is set to JOINED

  • Discriminator column name DTYPE and type String are left default

  • Discriminator value is set to C

Company.java entity:

  • Parent class is set to Client

  • Discriminator value is set to M

Person.java entity:

  • Parent class is set to Client

  • Discriminator value is set to P

The OrderEdit.java screen controller contain the Client selection components and logic.