Trying to sort a Composition list by a parent field... getting "Invalid Query Key"

This will be easier to see with a simple example - attached.

So I have a fairly simple structure - an invoice header, with a composition of lines. And a payment header, with its composition of payment lines. Each payment line has an association to an invoice line. And the invoice line entity in turn has a composition list of said payment lines. I want to sort that list by payment.dateReceived - a field of the parent of the payment line.

At runtime, this crashes with an Invalid query key exception.

How can I have that payment line list sorted by the dateReceived field of their parent Payment?

(The Designer even suggests this should work by showing order.date as a possible option in the “order by” box…)

orderbytesting.zip (88.4 KB)

Hi Jon,

Thanks for the test project.
Unfortunately, JPA supports nested properties in @OrderBy for collection properties only for embeddables. So we’ve recently removed the misleading prompt in the designer, see https://youtrack.jmix.io/issue/JST-3205/Change-prompt-in-Order-by-field-of-collection-attribute

So you have to sort items programmatically, for example in the data container after everything is loaded. For example:

@Subscribe
public void onAfterShow(AfterShowEvent event) {
    myNestedDc.getDisconnectedItems().sort(Comparator.comparing(MyEntity::getSortValue));
}
1 Like