Filter by discriminator value


in my app I have an inheritance strategy for a set of entities. Say root, and A,B,C as inherited entities.

If I set up a browser screen on the root type, it works fine and am able to navigate to each corresponding edit screen, which corresponds to the default CUBA behavior. Very nice.

However what I am not being able to achieve is to filter between A,B or C entities based on a filter condition. So the type of entity is not an available filter condition, hence not being able to easily select in the browser screen, instances of each type. In the definition of the entities I use the @DiscriminatorValue annotation.

My first approach was to create a transient @MetaProperty, and based on java instance type, return a discriminator value. That works well for display purposes, then I am able to retrieve the object type and display it on screen in the root entity browser. However I am not being able to filter based on the value of that property. Presumably filter is much more intimately tied to the inner hibernate workings (or persistence mechanism) and therefore I don’t see any other solution than artificially adding a persistent property in my root entity which explicitly stores the type of entity.

That’s a valid solution for me, but I was wondering if CUBA has a more elegant way to solve this problem.

Thanks in advance for reading me.


Carlos Conti.


If you need proper filtering, you’d better override load process by installing a data loader delegate as described here: Data Loaders - CUBA Platform. Developer’s Manual This approach requires some manual coding, but it will work properly and won’t be affected by CUBA updates.

As an experiment you may try to use single table inheritance model and publish the discriminator field explicitly:

@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DTYPE", discriminatorType = DiscriminatorType.STRING)
@Table(name = "DIALOGS_NAMED")
@Entity(name = "dialogs_Named")
public class Named extends StandardEntity {
    private static final long serialVersionUID = 7433361674348324320L;

    @Column(name = "NAME", nullable = false)
    private String name;

    public String getName() {
        return name;

    public void setName(String name) { = name;

    @Column(name = "DTYPE", insertable = false, updatable = false)
    private String dtype;

    public String getDtype() {
        return dtype;

    public void setDtype(String dtype) {
        this.dtype = dtype;


After that, you should be able to filter entities by type, I did a quick prototype, it worked for me. Just do not forget to hide dtype from UI. And remember, it works, but It looks like a hack, so I wouldn’t rely on this too much.


See this related discussion: Get discriminator (DTYPE) - CUBA.Platform

Most likely an enum will help you out here and is a much cleaner and more extensible solution.


Thanks both for your ideas.

Mario do you mean to create an association field type enum? Yes something similar I had in mind. Pls confirm.