ebean icon indicating copy to clipboard operation
ebean copied to clipboard

Investigate allowing an entity to extend entity ( ~"Customization" )

Open rbygrave opened this issue 2 years ago • 0 comments

Normally @Entity beans can not extend another @Entity bean without using the inheritance annotations and discriminator column.

What this is about is allowing an @Entity bean to extend another @Entity. There are 2 use cases that I have in mind that I think this could be useful for.

  1. Customisation
  2. Logical replication

Customisation

With this, we have existing models (entity beans) and we can't or don't want to modify those entity beans. Either we didn't author them ourselves or they represent some common or core functionality that can be extended.

We are authoring an extension that uses the common entity beans but for the purposes of this extension we desire additional columns on an entity. With this we can create a new entity that extends another and adds properties/columns.

Under the hood:

  • The custom extension entity becomes the actual entity that drives DDL generation, and is the actual entity that the other entity beans joins to.
  • The existing/common/core entity ... actually turns into a "view based entity" which means it doesn't create DDL.
  • We can use both entity types for queries ... but they result in fetching back the extended entity
  • We can persist both entity types

Logical replication

The other potential use case is where we are using logical replication. We have a common/central table (say product) and this is logically replicated to a few other databases. Logical typically replication requires that the destination table has at LEAST the columns of the source table but it can have ADDITIONAL columns. This exactly matches what this feature allows. For example, a service extends Product to have its own ProductCustom entity with additional columns specific to that service.

rbygrave avatar May 17 '22 01:05 rbygrave