Bug with dataGrid aggregation and identity columns

I believe there is a bug when using aggregation on dataGrids. I’m using Jmix 2.2.1 and studio 2.2.2-241.

I have two entities, Order and OrderLineItem, with a one-to-many relationship. Each entity uses an Integer identity column.

The Order detail view contains a dataGrid of OrderLineItems. The create/edit/remove actions behave as expected when no aggregation is used. However, if aggregatable is enabled and I attempt to sum a column, I can no longer create new entities. I receive an error message: IllegalArgumentException: entity or id is null.

If I use a Jmix generated Integer id using @JmixGeneratedValue rather than @GeneratedValue(strategy = GenerationType.IDENTITY), I’m able to use aggregation and create new line items from the order detail view.

Aggregation with tables worked properly with Jmix 1.5.5 using Integer identity columns. Below are the first few lines of the stack trace. I’ve posted a sample project on GitHub.

java.lang.IllegalArgumentException: entity or id is null
	at io.jmix.core.common.util.Preconditions.checkNotNullArgument(Preconditions.java:101)
	at io.jmix.flowui.model.impl.CollectionContainerImpl.getItemIndex(CollectionContainerImpl.java:123)
	at io.jmix.flowui.model.impl.CollectionContainerImpl.getItemOrNull(CollectionContainerImpl.java:117)
	at io.jmix.flowui.model.impl.CollectionContainerImpl.getItem(CollectionContainerImpl.java:108)
	at io.jmix.flowui.data.grid.ContainerDataGridItems.getItemValue(ContainerDataGridItems.java:208)
	at io.jmix.flowui.data.aggregation.impl.AggregatableDelegate.lambda$valuesByProperty$0(AggregatableDelegate.java:197)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:720)

Has an issue been created for this bug? I’ve tried upgrading from Jmix 2.2.1 to 2.2.3 but the problem persists.

I need to use identity columns for my id attributes. Not having the ability to add rows in a datagrid that uses aggregation is quite an inconvenience, particularly since this worked in Jmix 1. If aggregatable is not set, I can add rows just fine. If aggregatable is set to true, I get the entity/id error above.

One other thing: in Jmix 2.2.1 you could include a composition attribute when creating the detail view, and the datagrid would include create/edit/remove buttons and actions. In Jmix 2.2.2 (and 2.2.3), the buttons/actions are not created. I don’t know if that was an intentional change, but it’s much nicer to have them automatically created.

I’m hoping the aggregation issue can be resolved in the upcoming 2.3 release. If it’s not going to be fixed, could someone respond to my post? Thanks!

Hi,

Could you please attache a demo project that reproduces the issue?

Regards,
Gleb

Attached find a simple project with two entities: Order and OrderLineItem. If you attempt to add an OrderLineItem from the Order detail view, you’ll get the error: entity or id is null. If aggregatable is unchecked, then line items can be created.

Thanks for looking into this!

aggregationBug.zip (109.1 KB)

Hi!

Thank you for your report.
It really was a bug. I created an issue: DataGrid aggregation doesn't work with composite entities · Issue #3253 · jmix-framework/jmix · GitHub.

A fix will be available in an upcoming release.
All detailed information is in the task. In short:

The error occurred because the io.jmix.core.entity.EntityValues#getId method was used as aggregation items ID provider.

Since composite entities receive their ID only after the parent entity is saved, this method of getting the ID would throw an error. Now io.jmix.core.entity.EntityValues#getIdOrEntity will be used.

Best regards,
Dmitriy

1 Like