Join tables with association to entities with Join Inheritance


I have two, kind of basic entities (A, B), with both basic attributes, both ManyToOne joined attributes.

When I want to join them in a browser, I use ValueCollectionDatasource. I tried multiple JPQL queries, which all basiclly join the 2 entities on an associated entity (they both have attribute X, which is an association).

The join happens beautifully, however when I want to reach for an associated attribute (Y) in A, I get the unfetched attribute error and I can’t for the life of me figure out how to solve it.

I tried creating a non-persistant entity © with association to A, B. I then tried using a collection datasource for class C and 2 nested datasources for A, B. This seemed like a good solution, since I can set the view for A, B, in order to gain access to the attributes I couldn’t reach before. I wrote a JPQL script, which takes the 2 nested datasources and selects the values where attribute X is equal on both.
However, in this case I got the error: “Datasource couldn’t depend from two different sources”, which I don’t understand, since depending on only one datasource makes the outer datasource kindof pointless imo.

Can somebody provide me a solution on this topic?

Thanks in advance

P.S.: attribute Y is coming from a superclass, with JOINED inheritance. Idk if it changes anything in this case.

Maybe I can rephrase the question from a more generic aproach:

I have 2 entities (A, B). I want them to appear in one table, joined by attribute X, without creating a persistent entity with a DB table. I also need to be able to print MetaProperites, which makes it impossible to just use a ValueCollectionDatasource (afaik at least), because I can’t load an attribute (Y) into an entity, because I’ll only get the instance of Y, or the entity with attribute Y nulled. I also cannot load a MetaProperty, irrelevant of the fact that I set the related field for given MetaProperty, which closes all windows of opportinuty to actually get this to work.

Another way could be to merge 2 collectionDs into one, however I get the above mentioned error message, saying CUBA doesn’t support 2 Ds dependency.

And now here I am, out of ideas.

Hi László,

If I understand your problem correctly, you want to display in one table two entities which have no explicit relation, and the table should also display attributes of some related entities. So let’s consider this model:

@Entity(name = "teot$Foo")
public class Foo extends StandardEntity {
    @Column(name = "F1")
    protected String f1;

    @Column(name = "F2")
    protected String f2;

    @Column(name = "F3")
    protected String f3;

@Entity(name = "teot$Bar")
public class Bar extends StandardEntity {
    @Column(name = "B1")
    protected String b1;

    @Column(name = "B2")
    protected String b2;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "BAZ_ID")
    protected Baz baz;

@Entity(name = "teot$Baz")
public class Baz extends StandardEntity {
    @Column(name = "Z1")
    protected String z1;

    @Column(name = "Z2")
    protected String z2;

Let’s also assume that Foo.f1 = Bar.b1. Then the following JPQL in a ValueCollectionDatasource will load both entities and related Baz.z1 field:

select f.f1, f.f2, b.b2, b.baz.z1
from teot$Foo f, teot$Bar b
where f.f1 = b.b1

See the sample project attached. (90.9 KB)

Regarding the message about inability to depend on multiple datasources. You can easily circumvent the problem if you define a dependency on a single datasource, and set the second parameter programmatically. I.e. you add ItemChangeListener to the second datasource and invoke refresh() on the dependent datasource in it, passing the current item as the second parameter.