Ability to load all attributes of inherited entities with a single query
At least with the following constraints:
- Single-table inheritance
- Only local attributes (references could be loaded lazily)
With these limitations, the following code that works directly through EclipseLink's EntityManager does the job:
TypedQuery<Parent> query = em.createQuery("select p from Parent p", Parent.class);
List<Parent> entities = query.getResultList();
Jmix currently always applies a _base fetch plan for the parent entity (even if don't specify it explicitly) and hence cuts off child attributes.
See also forum topic, #2860, #4342.
See also changes in https://github.com/jmix-framework/jmix/issues/4068.
Inheritor collection attributes are wrapped in value holders properly now. Single reference properties may be added too by modifying mapping.isCollectionMapping() condition at org.eclipse.persistence.internal.descriptors.ObjectBuilder#buildAttributesIntoWorkingCopyClone:2115[4.0.6-3-jmix].
Then only one problem remains. Inheritor attribute must be present in _persistence_fetchGroup of the entity according to enhanced getter:
protected List _persistence_get_children() {
this._persistence_checkFetched("children");
return this.children;
}
public void _persistence_checkFetched(String var1) {
if (!this._persistence_isAttributeFetched(var1)) {
EntityManagerImpl.processUnfetchedAttribute(this, var1);
}
}
public boolean _persistence_isAttributeFetched(String var1) {
return this._persistence_fetchGroup == null || this._persistence_fetchGroup.containsAttributeInternal(var1);
}
So the task is to put all inheritor reference attributes to FetchGroups of inheritors after entity loaded.
Unfortunately, attributes cannot be added to FetchGroup of the query because Eclipselink will not find them in parent class and throw validation exception.