Table of Contents

Let the problem

Diagram

To explain how lazy loading work in Adichatz, have a look on this diagram:

  • An Adress depends on one and only one City.
  • A City could have zero or several Adresses.
  • A City depends on one and only one Country.

POJOs corresponding to this schema can be consult here.

With Hibernate, we can retrieve adress number 1 by using:

Adress address = (Adress) entityManager.find(Adress.class,1);

If I try something like that:

String cityName = address.getCity().getCity();
I will obtain a LazyIntializationException. That is normal because the fetch points to FetchType.LAZY in the ManyToOne relationship, so the city field loaded by Hibernate is only a proxy. So you have to manage this issue.

Adichatz provides a solution:

  • Copy CustomerDIGENERATED.axml file to CustomerDI.axml which will become the reference for generated code.
  • In the city field replace convertModelToTarget element as following:

<refText property="city" style="SWT.BORDER | AdiSWT.FIND_BUTTON | AdiSWT.DELETE_BUTTON" id="city">
    <convertModelToTarget>return &quot;City:&quot; + #FV().city + &quot; - Country:&quot; + #FV().Country.country;</convertModelToTarget>
</refText>

The displayed value would be in the generated JAVA class:

return "City:" + ((Address) value).getCity().getCity() + " - Country:" + ((Address) value).getCity().getCountry().getCountry();

No exception occurs!


How it works

The bean adress is wrapped into an Entity which is managed by the Application Data Cache. Adichatz associates a “decision tree” with each Entity. In this case the decision tree will be like this: Entity Adress number 1

  • + city
    • - city
    • + Country
      • - country

If in another editor, you want to display the number of adresses for the city, the decision tree becomes: Entity Adress number 1

  • + city
    • - name
    • - adresses
    • + Country
      • - country

In order to optimize calls to the server before displaying a page, Adichatz lists all the needed values (lazy loadings). If at least one is not initialized, it ask to reinitialize the decision tree to the server for all the entities having a missing value.
This feature is entirely compliant with databinding process and ensures consistency between different editors.

2020/04/16 10:56