Get discriminator (DTYPE)

Would be very interesting to improve Parent-Extended entities management, adding a simple way to get discriminator.

entity.getDiscriminatorFieldName() -> returns the name of discriminator field, if it is set, or null if not
entity.hasDiscriminator() -> returns (this.getDiscriminatorFieldName() !=null)
entity.getDiscriminatorValue() -> returns value of discriminator field, or exception “No discriminator”.

hi,

from my previous experience with this magic DYTPE column there is not really a good way to map that to an entity property (or to have such an explicit property in the entities). There are a lot of shortcomings that are in different levels. In the JPA world it is problematic to get that mapped properly. When you google it outside the scope of CUBA you’ll find a few quite ugly solutions with various levels of problems. In the upper layers you also have certain requirements:

  • filter for a given type via the generic filter UI

It becomes even more messy when you have multiple levels of inheritance and you want to find out all elements that belong to a certain sub layer (and below). All of this stuff is not really working.

Therefore: the only way that i have seen it working properly with the ability to fulfill requirements even four weeks from your todays requirements is the following:

Create a dedicated Enum (CustomerType or something) that mirrors the entity inheritance. Then all of a sudden most of the problems go away. You only have to be careful that when you create the instances, but this can be done through some @PostConstruct annotations and alike.

Bye
Mario

2 Likes

Hi Mario
I already thought of something like your solution. However, the objective of this idea was to be able to give some kind of dynamic management, not dependent to know if this or that entity has been “manually prepared”.

I’m quite a rookie at JPA, and my knowledge, about it, is small. Thanks for your reply.

I like the idea of the enum. I might do that