This problem is really annoying and the current fix is really bad (too much queries, save problems because reload…)
I created 2 projects to explain it (jmix 1 and jmix 2 same bug).
The datamodel is an abstract BaseThirdParty entity with two concret entity LegalPerson and NaturalPerson. There is also a Case which has a owner of type BaseThirdParty and a list of Inspection with an agent of type NaturalPerson.
I generated screens (Entity list and detail views) without modification and a second screen for Case and Inspection where I selected owner and agent.
When I navigate on the application, I can go on
- BaseThirdParty browser and detail
- LegalPerson browser and detail
- NaturalPerson browser and detail
- Inspection browser and detail
- Inspection + agent browser and detail
- Case browser and detail
but I get an error on
- Case + owner browser and detail
java.lang.IllegalStateException: Cannot get unfetched attribute [firstname] from detached object com.company.sample2.entity.NaturalPerson-4af5c473-8a0e-259b-36df-2c93fd5bc871 [detached].
at org.eclipse.persistence.internal.queries.EntityFetchGroup.onUnfetchedAttribute(EntityFetchGroup.java:100) ~[org.eclipse.persistence.core-4.0.1-15-jmix.jar:na]
at io.jmix.eclipselink.impl.JmixEntityFetchGroup.onUnfetchedAttribute(JmixEntityFetchGroup.java:78) ~[jmix-eclipselink-2.1.3.jar:na]
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.processUnfetchedAttribute(EntityManagerImpl.java:2996) ~[org.eclipse.persistence.jpa-4.0.1-15-jmix.jar:na]
at com.company.sample2.entity.BaseThirdParty._persistence_checkFetched(BaseThirdParty.kt) ~[main/:na]
at com.company.sample2.entity.NaturalPerson._persistence_get_firstname(NaturalPerson.kt) ~[main/:na]
at com.company.sample2.entity.NaturalPerson.getFirstname(NaturalPerson.kt:15) ~[main/:na]
at io.jmix.core.entity.BaseEntityEntry.getAttributeValue(BaseEntityEntry.java:85) ~[jmix-core-2.1.3.jar:na]
at io.jmix.core.entity.EntityValues.getValue(EntityValues.java:100) ~[jmix-core-2.1.3.jar:na]
at io.jmix.core.impl.InstanceNameProviderImpl.getInstanceName(InstanceNameProviderImpl.java:147) ~[jmix-core-2.1.3.jar:na]
at io.jmix.core.MetadataTools.getInstanceName(MetadataTools.java:213) ~[jmix-core-2.1.3.jar:na]
at io.jmix.core.MetadataTools.format(MetadataTools.java:156) ~[jmix-core-2.1.3.jar:na]
at io.jmix.flowui.data.provider.StringPresentationValueProvider.apply(StringPresentationValueProvider.java:40) ~[jmix-flowui-2.1.3.jar:na]
at io.jmix.flowui.data.provider.StringPresentationValueProvider.apply(StringPresentationValueProvider.java:26) ~[jmix-flowui-2.1.3.jar:na]
at com.vaadin.flow.component.grid.Grid.applyValueProvider(Grid.java:1785) ~[vaadin-grid-flow-24.1.12.jar:na]
at com.vaadin.flow.component.grid.Grid.lambda$addColumn$63838bef$1(Grid.java:1773) ~[vaadin-grid-flow-24.1.12.jar:na]
at com.vaadin.flow.component.grid.ColumnPathRenderer$SingleValueProviderRendering.lambda$getDataGenerator$96b60bbc$1(ColumnPathRenderer.java:78) ~[vaadin-grid-flow-24.1.12.jar:na]
at com.vaadin.flow.data.provider.CompositeDataGenerator.lambda$generateData$0(CompositeDataGenerator.java:47) ~[flow-data-24.1.14.jar:24.1.14]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
I think the problem is in query.
2024-02-19T10:49:09.035+01:00 DEBUG 23076 --- [nio-8080-exec-5] eclipselink.logging.sql : <t 1135008119, conn 1735013723>
SELECT LIMIT ? ?
t3.ID AS a1, t3.CREATED_BY AS a2, t3.CREATED_DATE AS a3, t3.DELETED_BY AS a4, t3.DELETED_DATE AS a5, t3.LAST_MODIFIED_BY AS a6, t3.LAST_MODIFIED_DATE AS a7, t3.REFERENCE AS a8, t3.VERSION AS a9, t3.OWNER_ID AS a10,
t0.ID AS a11, t0.DTYPE AS a12, t0.CREATED_BY AS a13, t0.CREATED_DATE AS a14, t0.DELETED_BY AS a15, t0.DELETED_DATE AS a16, t0.FULLNAME AS a17, t0.LAST_MODIFIED_BY AS a18, t0.LAST_MODIFIED_DATE AS a19, t0.VERSION AS a20
FROM CASE_ t3 LEFT OUTER JOIN
(
BASETHIRDPARTY t0 LEFT OUTER JOIN LEGAL_PERSON t1 ON (t1.ID = t0.ID)
LEFT OUTER JOIN NATURAL_PERSON t2 ON (t2.ID = t0.ID)) ON (t0.ID = t3.OWNER_ID)
WHERE (t3.DELETED_DATE IS NULL
)
bind => [0, 50]
I think that FROM is OK but the problem in the SELECT there is no field from LEGAL_PERSON t1 or NATURAL_PERSON t2 !