==== Let the problem ====
{{tutorial:diagram.png?500 |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 [[tutorial:pojo_schema|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:
return "City:" + #FV().city + " - Country:" + #FV().Country.country;
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 [[features:data_cache|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.