To explain how lazy loading work in Adichatz, have a look on this diagram:
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.
<refText property="city" style="SWT.BORDER | AdiSWT.FIND_BUTTON | AdiSWT.DELETE_BUTTON" id="city"> <convertModelToTarget>return "City:" + #FV().city + " - Country:" + #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();
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
If in another editor, you want to display the number of adresses for the city, the decision tree becomes: Entity Adress number 1
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.