Datamanager with Multiple Entities

Is it possible to use datamanager to query across multiple entities and return the result as a custom class object in Jmix?

For example: datamanager.load(CustomClass.class).query(“select a.status,b.orderNo from sample_Order a left outer join sample_Inventory b on a.item=b.item where b.qty>5”).list();

@mmckenzie I did something similar, but there is no modeled “join-entity” as a result but a io.jmix.core.entity.KeyValueEntity as a result: Key-Value Containers :: Jmix Documentation

Are you aware of that?

@bank I had seen the documentation but I’m not sure how it would apply in my case. I am using the datamanager in a service that will be exposed through the REST API for an external application to consume.

You can convert a list of KeyValueEntity to the list of your custom objects as follows:

List<CustomClass> list = dataManager.loadValues("select a.status,b.orderNo " +
                "from sample_Order a left outer join sample_Inventory b on a.item=b.item " +
                "where b.qty>5")
        .properties("status", "orderNo") // give names to resultset fields
        .list()
        .stream()
        .map(kvEntity -> {
            return new CustomClass(kvEntity.getValue("status"), kvEntity.getValue("orderNo"));
        })
        .collect(Collectors.toList());

See also Loading Scalar and Aggregate Values.