OneToOne Plan Fetch

Hi,

I want always load oneToOne entity in abstract class in my core model like :

@JmixEntity(name = “…”)
@MappedSuperclass
public abstract class …

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = “STATUT_META_DATA_ID”)
protected StatutMetadataEntite statutMetadata;

Jmix: Jmix framework doesn’t support EAGER fetch type for relations

Only way use Lazy with custom fetchPlan that painfull because 95% i need it …

Let’s try EAGER :

  1. First complexe browse view i use keyValueCollection who have an Entity extends abstract
    work perfectly
    Nice, it 's faster …

  2. Load entity into edit view
    I receive Caused by: java.lang.RuntimeException: Unable to access value holder

Ok doesn’t support EAGER

Let’s try LAZY :

  1. Same complexe browse …
    too large entities … lazy not work …
    cannot use plan …

How can I do it? Peraphs I missing something …

best regards

Gabriel

Hello Gabriel!

Sorry for the late reply. Let’s look at what can be done in this situation.

The first question that comes to mind is: “What difference between ‘always loaded one-to-one entity’ and ‘embedded entity’? Maybe making StatutMetadataEntite @Embaddable and including it in abstract class as @Embedded property possible?” If so, it will solve all problems.

Otherwise, you can define your own custom fetch plan in fetch-plans.xml and use it in screens by name like _local, _base or _instance_name. I cannot see any inconveniences with it because some fetch plan have to be specified anyway and writing e.g. full instead of _local is not looks like a problem.

Maybe I misunderstood something? What exactly do you mean by:

too large entities … lazy not work …
cannot use plan …

Regards,
Dmitry

Hello
i migrate all MetaData to embedded entity.
But i have same problem inside my metadata with again OneToOne.

You can follow this exemple :
unfetch.zip (316.9 KB)
Gabriel

Hello Gabriel!

Sorry again for the late reply and thank you for the project, it makes the problem clear.
First of all, you can specify fetch plan in fetch-plans.xml:

<fetchPlans xmlns="http://jmix.io/schema/core/fetch-plans">
    <fetchPlan class="com.company.jmix_unfetch.entity.MyEntity" name="withMeta" extends="_base">
        <property name="metaEntity" fetchPlan="_base">
            <property name="lastentity" fetchPlan="_base">
                <property name="infoEntity" fetchPlan="_base"/>
            </property>
        </property>
    </fetchPlan>
</fetchPlans>

and use this plan where it needed (com.company.jmix_unfetch.screen.blank.BlankScreen#onReadClick):

   @Subscribe("read")
    public void onReadClick(Button.ClickEvent event) {
       List<MyEntity> entites =  dataManager.load(MyEntity.class).all().fetchPlan("withMeta").list();
       if(!entites.isEmpty()) {
           MyEntity myEntity = entites.get(0);
           if (myEntity != null) {
               InfoEntity res = myEntity.getMetaEntity().getLastentity().getInfoEntity();
           }
       }
    }

In terms of performance it is better to specify all necessary properties in fetch plan, than load them separately through lazy loading.

As for lazy loading and unfetched attribute problem, I will look closer to it and return with answer.

Regards,
Dmitry

Thx,
I try it today.
Peraphs I missing something but I can’t use abstract fetchplan in extends
image
In example my personneMorale entity extends masterData abstract class MappedSuperclass JmixEntity
I can’t do it with fetchPlan.
So i will be include all properties into personneMorale fetchPlan.
Gabriel

Hello Gabriel,

The issue has been created in order to fix lazy loading behaviour in described case. Thank you for reporting issue and providing project to reproduce it!

As for fetch plan extends problem, studio issue has been created, thank you for reporting this issue!

Framework actually works with ancestor entity fetch plan in extends.
E.g. despite of studio warning, these fetch plans will work in provided project:
изображение

Regards,
Dmitry