aerogear/TODO — pull request #6 by mstruk (2012-10-11 18:03:03+00:00)
Title: AEROGEAR-538 TODO app Login Issues on refresh

The problem is one of server side architecture. First a SLSB method is called on an endpoint which loads and returns some entities. Then those entities are passed on for serialization to output.

The problem is that all the relationship properties (OneToMany, ManyToMany) that are accessed in serialization layer have to be already loaded. That's because after SLSB method returns entites and before they are passed to serialization layer the persistence context is closed so lazy loading is no longer possible.

That is correct behaviour from the POV that serialization layer deals with blocking I/O, and we don't want active transaction to hang on blocked output.

But it means we need to know what properties we access during serialization, and we need to prefetch them.

Clean way of achieving that is to configure EAGER fetching, however it's likely that the result is overeager fetching. Finetuned fetching OTOH requires to not use EAGER fetching, and to perform a more fine-tuned querying in each of the endpoint methods, which is a lot more work, resulting in a more intimidating code.

For now I use EAGER fetching with additional Hibernate specific JOIN fetching to avoid N+1 problem. With that we may get a different problem when loading Projects with great number of tasks, and great usage of tags on those tags. That would result in huge resultsets so it might at some point possibly become slower than without that optimization.